Error in accessing google reader's Endpoints API

爷,独闯天下 提交于 2019-12-02 19:38:09

问题


I am trying to implement google reader in iPhone APP and so far I have successfully received the sid and auth. The problem arises when I try to call the Endpoints API with GET.. Here's the code:

 ASIHTTPRequest *request = [self requestForAPIEndpoint:@"https://www.google.com/reader/api/0/subscription/list?output=json"];
 [request setDelegate:self];
 [request startAsynchronous];

- (ASIHTTPRequest *) requestForAPIEndpoint: (NSString *) apiEndpoint
{
 ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: apiEndpoint]];
[request addRequestHeader: @"User-Agent" value: @"YourClient"];
 [request addRequestHeader: @"Cookie" value: signature];
 NSLog(@"Sig = %@",signature);
 [request addRequestHeader: @"Authorization" value: autho];
 return request.
}

The autho and signature are correctly set. However every-time I get callback in - (void)requestFailed:(ASIHTTPRequest *)request method. What is that I am doing wrong?? Do I need to register some where to access the API and set the user-agent to that name??

I modified the requestForAPIEndpoint method as follows then also I have the same problem.

- (ASIHTTPRequest *) requestForAPIEndpoint: (NSString *) apiEndpoint
{

NSDictionary *properties = [[[NSMutableDictionary alloc] init] autorelease];
[properties setValue:signature forKey:NSHTTPCookieValue];
[properties setValue:@"SID" forKey:NSHTTPCookieName];
[properties setValue:@".google.com" forKey:NSHTTPCookieDomain];
[properties setValue:@"1600000000" forKey:NSHTTPCookieExpires];
[properties setValue:@"/" forKey:NSHTTPCookiePath];
NSHTTPCookie *cookie = [[[NSHTTPCookie alloc] initWithProperties:properties] autorelease];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: apiEndpoint]];
[request setUseCookiePersistence:NO];
[request setRequestCookies:[NSMutableArray arrayWithObject:cookie]];

[request addRequestHeader: @"User-Agent" value: @"YourClient"];
[request addRequestHeader: @"Authorization" value: autho];
 return request;
} 

回答1:


You don't need to provide the SID cookie if you are using ClientLogin (via the Authorization header). See http://code.google.com/p/google-reader-api/wiki/Authentication for the supported authentication schemes.

Additionally, the Authorization header should be formatted as GoogleLogin auth=<auth token> where <auth token> is the Auth value from the ClientLogin response.



来源:https://stackoverflow.com/questions/8229019/error-in-accessing-google-readers-endpoints-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!