【发布时间】:2014-07-11 23:56:58
【问题描述】:
这是使用 obj-c 的代码 ..我收到“未找到授权码”错误但无法解决。我尝试了几种选择
错误:{"error":"oauth2_error","error_description":"未找到授权码"}
案例 1: NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"https://api.home.nest.com/oauth2/access_token?code=%@&client_id=xxx&client_secret=xxx&grant_type=authorization_code,code]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *error;
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
案例 2: NSString *post = [NSString stringWithFormat:@"client_id=xxx&client_secret=xxx&grant_type=authorization_code&code=%@", code];
NSLog(@"Post -%@",post);
NSData * postData = [post dataUsingEncoding:NSUTF8StringEncoding]; //tried ascii too
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"https://api.home.nest.com/oauth2/access_token"]];
NSLog(@"url-%@",url);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
我的步骤: 1.使用LHOAuth2LoginViewController 2. 打开网页视图 3.用户输入电子邮件/密码登录Nest 4、提示“Works with Nest” 5.用户“接受” 6.重定向到本地主机 7.截获“授权码” 8.使用NSUrlConnection传递Auth code获取Auth Token 9. 获取oauth2_error: "authorization code not found"
【问题讨论】:
-
能否请您在帖子正文中发送查询参数并重试请求?
-
我也试过了..
标签: nest-api