views:

706

answers:

2

I am able to 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.

+1  A: 

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.

outis
OMG YOU ARE MY SAVIOR
JustinXXVII
A: 

Hey!

Could you please PLEASE give me some information on where I can find tutorials or help for implementing Google Reader into my Mac/iPhone/iPad app?

I'd really appreciate that!

Thank you VERY much

Artur

Artur