2010-05-05 1 views
3

Google 리더 계정에 대한 SID (SessionID)를 성공적으로 가져올 수 있습니다. Google 리더에서 피드를 가져와 다른 작업을 수행하려면 승인 토큰을 얻어야합니다. 이 일을하는 데 문제가 있습니다. 누군가가 약간의 빛을 비출 수 있습니까?Objective-C가있는 Google 리더 API - 토큰 가져 오는 중 문제가 발생했습니다.

//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]; 

Google의 응답으로 403 Forbidden 오류가 표시됩니다. 아마 제대로하지 않을거야. NSHTTPCookie에 대한 문서에 따라 사전 값을 설정합니다.

답변

1

쿠키 속성의 키는 리터럴 문자열이 아닌 NSHTTPCookie constants이어야합니다.

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

값 상수는 해당 이름과 같지 않습니다. 일반적으로 말하면 "NSHTTPCookie"가없는 이름으로 표시됩니다 (예 : NSHTTPCookieDomain == @"Domain"). 그러나 이것에 의존해서는 안됩니다. 문서를 다시 읽으십시오.

+0

너는 나의 구세주가된다. – Justin