Withings API不支持node-oauth

问题描述 投票:3回答:3

我正在尝试使用Withings API验证对node-oauth的请求,here是一个广泛使用的节点OAuth模块。 OAuth流程的所有首字母步骤都正常工作,我可以获取用户ID,访问令牌和访问令牌密钥。但是,在尝试实际使用这些令牌进行身份验证请求时,我会收到以下错误之一:

  • 2554错误的操作或错误的Web服务
  • 2555发生未知错误
  • 2556未定义服务

我已经通过测试var consumerKey = ""; var consumerSecret = ""; var oauth_access_token = ""; var oauth_access_token_secret = ""; var userid = ""; var oauth = require("oauth"); var withings = new oauth.OAuth( "https://oauth.withings.com/account/request_token", "https://oauth.withings.com/account/access_token", consumerKey, consumerSecret, "1.0", null, "HMAC-SHA1" ); var url = "http://wbsapi.withings.net/measure?action=getmeas&userid=" + userid; withings.get(url, oauth_access_token, oauth_access_token_secret, function(error, response) { console.log(response); }); 验证了我使用的凭据是有效的。我做错了什么,或者是以某种非标准的方式实现了Withings API,这使得它与node-oauth不兼容?

{"status":2554}

输出:

signUrl
javascript node.js oauth withings
3个回答
4
投票

我想出了这一个。 node-oauth库假定大多数API都希望在头文件中定义OAuth参数。但是,OAuth参数也可以在查询字符串中定义,这就是Withings决定实现它的方式。 node-oauth库为此目的定义了get函数,但您必须明确使用它。在该函数中包装URL后,问题就解决了。请注意,不需要将访问令牌传递到var url = withings.signUrl("http://wbsapi.withings.net/measure?action=getmeas&userid=" + userid, oauth_access_token, oauth_access_token_secret); withings.get(url, null, null, function(error, response) { console.log(response); }); 函数,因为请求已经签名。

https://wbsapi.withings.net/measure?action=getmeas&category=1&access_token=XXXXXxxxxxxxxXXXXX&meastype=1&startdate=1543581749&enddate=1543581750

0
投票

withings API可能有点特别且非常反复无常。例如,如果您没有按正确的顺序发送查询字符串中的选项,则有时会出错。我没有尝试过node-oauth,因为我在角色和Rails中的朋友一起工作,但很难让它工作。

我没有看到你的回调网址发送在node-oauth的选项中你是否在Withings应用程序的选项中更改了它?

您可以尝试修改node-oauth以记录每次调用Withings的响应,并查看它是第一个,第二个还是第三个失败的人。

祝好运 ;)


0
投票

检查你的网址可能是你错过了任何所需的参数,如访问令牌。

示例网址:qazxswpoi

© www.soinside.com 2019 - 2024. All rights reserved.