我在之前的 stackoverflow.com 帖子中遇到了同样的问题。
具体来说,我似乎能够正确获取“Auth”令牌,但是当我访问后面的页面时尝试在标题中使用它仍然只是返回给我登录页面的 HTML。
通过与这篇文章相关的链接,我确定您需要对该 URL进行后续调用。
然后,对 URL 的调用将为您提供一个 ACSID cookie,然后需要在后续调用中传递该 cookie 以保持经过身份验证的状态。
在请求此 cookie 时,我已阅读各种帖子,说您需要通过将原始身份验证令牌附加到查询字符串来指定原始身份验证令牌,以便:
?auth=this_is_my_token
我还读到您应该按照google 文档中的说明在 http 标头中设置它,以便 http 标头名称/值是:
Authorization: GoogleLogin auth=yourAuthToken
我已经尝试了这两种方法,但没有看到任何返回的 cookie。我使用了 Wireshark、Firefox 的 LiveHttpHeaders 和简单的 NSLog 语句,试图查看是否返回了类似的内容。
下面是我一直在使用的代码片段。
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://yourapp.appspot.com/_ah/login?auth=%@", [token objectForKey:@"Auth"]]];
NSHTTPURLResponse* response;
NSError* error;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:[NSString stringWithFormat:@"GoogleLogin auth=%@", [token objectForKey:@"Auth"]] forHTTPHeaderField:@"Authorization"];
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//show me all header fields
NSLog([[response allHeaderFields] description]);
//show me the response
NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]);
NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://yourapp.appspot.com/_ah/login"]];
//show me all cookies
for (NSHTTPCookie *cookie in all)
{
NSLog(@"Name: %@ : Value: %@", cookie.name, cookie.value);
}
我希望您可以使用ClientLoginGoogle App Engine 代码。