开发者

Google Reader API with Objective-C - Problem getting token

开发者 https://www.devze.com 2022-12-29 08:23 出处:网络
I am able to开发者_JAVA技巧 successfully get the SID (SessionID) for my Google Reader account.In order to obtain the feed and do other operations inside Google Reader, you have to obtain an authorizat

I am able to开发者_JAVA技巧 successfully get the SID (SessionID) for my Google Reader account. In order to obtain the feed and do other operations inside Google Reader, you have to obtain an authorization token. I'm having trouble doing this. Can someone shed some light?

//Create a cookie to append to the GET request
NSDictionary *cookieDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"SID",@"NSHTTPCookieName",self.sessionID,@"NSHTTPCookieValue",@".google.com",@"NSHTTPCookieDomain",@"/",@"NSHTTPCookiePath",nil];
NSHTTPCookie *authCookie = [NSHTTPCookie cookieWithProperties:cookieDictionary];

//The URL to obtain the Token from
NSURL *tokenURL = [NSURL URLWithString:@"http://www.google.com/reader/api/0/token"];
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];

//Not sure if this is right: add cookie to array, extract the headers from the cookie inside the array...?
[tokenRequest setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:[NSArray arrayWithObjects:authCookie,nil]]];

//This gives me an Error 403 Forbidden in the didReceiveResponse of the delegate
[NSURLConnection connectionWithRequest:tokenRequest delegate:self];

I get a 403 Forbidden error as the response from Google. I'm probably not doing it right. I set the dictionary values according to the documentation for NSHTTPCookie.


The keys of a cookie properties should be the NSHTTPCookie constants, not literal strings as you give them.

NSDictionary *cookieDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"SID",NSHTTPCookieName,
          self.sessionID,NSHTTPCookieValue,
          @".google.com",NSHTTPCookieDomain,
          @"/",NSHTTPCookiePath,
          nil];

Note that the values constants aren't equal to their names; generally speaking, they appear to be the name without the "NSHTTPCookie" (e.g. NSHTTPCookieDomain == @"Domain"), but you shouldn't rely on this. Re-read the documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消