如何将经过身份验证的请求发送到Google Reader?

编程入门 行业动态 更新时间:2024-10-11 19:13:37
本文介绍了如何将经过身份验证的请求发送到Google Reader?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

似乎Google禁用了向其Google数据服务(特别是Google Reader)发送Cookie SID的旧方法.

It seems that Google has disabled the old way of sending cookie SID to their Google Data Services, specifically Google Reader.

这种方式至少不能正常工作对我来说:

This way does not work at least for me:

//create request NSString* content = [NSString stringWithFormat:@"accountType=HOSTED_OR_GOOGLE&Email=%@&Passwd=%@&service=ah&source=myapp", [loginView username].text, [loginView password].text]; NSURL* authUrl = [NSURL URLWithString:@"www.google/accounts/ClientLogin"]; NSMutableURLRequest* authRequest = [[NSMutableURLRequest alloc] initWithURL:authUrl]; [authRequest setHTTPMethod:@"POST"]; [authRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"]; [authRequest setHTTPBody:[content dataUsingEncoding:NSASCIIStringEncoding]]; NSHTTPURLResponse* authResponse; NSError* authError; NSData * authData = [NSURLConnection sendSynchronousRequest:authRequest returningResponse:&authResponse error:&authError]; NSString *authResponseBody = [[NSString alloc] initWithData:authData encoding:NSASCIIStringEncoding]; //loop through response body which is key=value pairs, seperated by \n. The code below is not optimal and certainly error prone. NSArray *lines = [authResponseBody componentsSeparatedByString:@"\n"]; NSMutableDictionary* token = [NSMutableDictionary dictionary]; for (NSString* s in lines) { NSArray* kvpair = [s componentsSeparatedByString:@"="]; if ([kvpair count]>1) [token setObject:[kvpair objectAtIndex:1] forKey:[kvpair objectAtIndex:0]]; } //if google returned an error in the body [google returns Error=Bad Authentication in the body. which is weird, not sure if they use status codes] if ([token objectForKey:@"Error"]) { //handle error };

和请求:

TTURLRequest *request = [TTURLRequest requestWithURL:url delegate:self]; request.cachePolicy = cachePolicy; request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER; NSString *cookieHeader = [NSString stringWithFormat:@"Name=SID;SID=%@;Domain=.google;Path=/;Expires=160000000000", sid]; [request setValue:cookieHeader forHTTPHeaderField:@"Cookie"]; [request setHttpMethod:@"GET"]; [request setValue:@"myapp" forHTTPHeaderField:@"User-agent"];

更改为使用GoogleLogin auth = xxx会给我一个NSURLErrorDomain 401

Changing to use the GoogleLogin auth=xxx gives me a NSURLErrorDomain 401

TTURLRequest *request = [TTURLRequest requestWithURL:url delegate:self]; request.cachePolicy = cachePolicy; request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER; NSString *authorizationHeader = [NSString stringWithFormat:@"GoogleLogin auth=%@", auth]; [request setValue:authorizationHeader forHTTPHeaderField:@"Authorization"]; [request setHttpMethod:@"GET"]; [request setValue:@"myapp" forHTTPHeaderField:@"User-agent"];

结果始终是401错误代码.有人可以告诉我如何解决此特定情况吗?预先谢谢你.

The result is always the 401 error code. Could someone show me how to fix in this specific case? Thank you in advance.

Error Domain=NSURLErrorDomain Code=401 "Operation could not be completed. (NSURLErrorDomain error 401.)" Error description: Operation could not be completed. (NSURLErrorDomain error 401.)

推荐答案

更改POST的正文可以解决401错误. service,source和& continue.

Changing the body of the POST solves the 401 error. Differences are in the service, source & continue.

NSString* content = [NSString stringWithFormat:@"Email=%@&Passwd=%@&service=reader&source=yourapp&continue=www.google", username, password];

更多推荐

如何将经过身份验证的请求发送到Google Reader?

本文发布于:2023-11-15 16:20:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   如何将   身份验证   Reader   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!