问题描述
我正在尝试在iPhone APP中实施谷歌阅读器,到目前为止,我已成功收到 sid 和身份验证。当我尝试使用 GET 调用Endpoints API时出现问题。这是代码:
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.
}
正确设置了autho和签名。但是每当我得到回调 - (void)requestFailed:(ASIHTTPRequest *)请求方法。我做错了什么?我是否需要注册访问API的位置并将用户代理设置为该名称?
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??
我将 requestForAPIEndpoint 方法修改为然后我也有同样的问题。
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;
}
推荐答案
你不需要如果您使用ClientLogin(通过授权
标头),请提供SID cookie。请参阅。
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.
此外,授权
标头应该是格式为 GoogleLogin auth =< auth token>
其中< auth token>
是来自ClientLogin响应的Auth
值。
Additionally, the Authorization
header should be formatted as GoogleLogin auth=<auth token>
where <auth token>
is the Auth
value from the ClientLogin response.
这篇关于访问谷歌阅读器的端点API时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!