【问题标题】:NEST API AUTH ERROR - authorization code not found/iosNEST API AUTH ERROR - 未找到授权代码/ios
【发布时间】: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


【解决方案1】:

查看 Nest 开发者网站上的示例 iOS-NestDK 项目。具体来说,请查看 NestAuthManager 文件,并随时在您的项目中使用它。

干杯, 雷蒙德

【讨论】:

  • 样本没有帮助。运行示例时出现同样的错误:“检索授权码时出错”
猜你喜欢
  • 2019-05-03
  • 2023-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多