2011-11-22 32 views
0

我想實現谷歌閱讀器在iPhone APP,到目前爲止,我已經成功地接收到SIDAUTH。當我嘗試調用與終結點​​API GET問題就出現了..下面的代碼:錯誤在訪問谷歌閱讀器的端點API

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的位置並將用戶代理設置爲該名稱?

我修改了requestForAPIEndpoint方法如下,那麼我也有同樣的問題。

- (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; 
} 

回答

2

你並不需要,如果你正在使用的ClientLogin(通過Authorization頭),以提供SID的cookie。有關支持的身份驗證方案,請參閱http://code.google.com/p/google-reader-api/wiki/Authentication

此外,Authorization標頭應格式化爲GoogleLogin auth=<auth token>其中<auth token>是來自ClientLogin響應的Auth值。

+0

也刪除SID cookie後,沒有變化。該響應再次失敗。 – Shri

+0

代碼中'autho'變量的值是什麼?預期的格式是'GoogleLogin auth = ',其中''是您從ClientLogin獲得的內容。 –

+0

Autho只是auth id ..當我將它更改爲GoogleLogin auth = 時它像魅力一樣工作.. Thanx很多。如果您可以編輯並將其放入答案中,我將選擇此項作爲接受。 – Shri