Google Reader API using Objective-C - problem with getting token

I can successfully get the SID (SessionID) for my Google Reader account. To get a feed and perform other operations inside Google Reader, you need to get an authorization token. I have problems with 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 403 Forbidden error as a response from Google. I'm probably not doing it right. I set the dictionary values ​​according to the documentation for NSHTTPCookie.

+3
source share
1 answer

The cookie property keys should be NSHTTPCookieconstants , not literal strings, as you give them.

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

, ; , , -, "NSHTTPCookie" (, NSHTTPCookieDomain == @"Domain"), . .

+1

Source: https://habr.com/ru/post/1744069/


All Articles