我正在尝试从谷歌阅读器获取我的 iPhone 项目的令牌。我能够获得授权,但是当我请求令牌时,我得到 403 Forbidden
下面是我的代码实现。任何帮助,将不胜感激。
//The tokenStorer contains the Authorization key
NSString *tokenStorer = [[NSUserDefaults standardUserDefaults]valueForKey:@"authKey"];
NSLog(@"%@", tokenStorer);
NSDictionary *cookieDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"www.google.com", @"Host",
@"iReader", @"User-Agent",
@"gzip, deflate", @"Accept-Encoding",
tokenStorer, @"Authorization",
nil
];
//@"Auth", NSHTTPCookieName, tokenStorer, NSHTTPCookieValue, @"./google.com", NSHTTPCookieDomain, @"/", NSHTTPCookiePath, nil];
//NSHTTPCookie *authCookie = [NSHTTPCookie cookieWithProperties:cookieDictionary];
//Google token url "http://www.google.com/reader/api/0/token?client=clientName"
NSURL *url=[[NSURL alloc] initWithString:GOOGLE_READER_TOKEN_URL];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]initWithURL:url];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setAllHTTPHeaderFields:cookieDictionary];
NSData *reciveData;
NSURLResponse *response;
NSError *error;
reciveData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSMutableURLRequest *tokenRequest= [[NSMutableURLRequest alloc] initWithURL:url];
NSString *trial = [[NSString alloc]initWithData:reciveData encoding:NSASCIIStringEncoding];
NSLog(@"%@ %d",trial, response);
[url release];