0

全部

我有一个使用 Withing 的 api 和 OAuth 成功获得授权的应用程序。

我从 whitings 获得了身份验证页面,并获得了生成的令牌和验证程序,但是我无法使用这些请求 - 我不断收到 342 错误:签名(使用 Oauth)无效。

代码:

<?
require("include.php");
require_once("OAuth.php");


$domain = "oauth.withings.com";
$base = "/account/";
$base_url = "https://$domain$base";

$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$consumer = new OAuthConsumer("my key goes here :-)", "my key goes here :-)", "http://oauth.corp.withings.com/test.php");

$sig_method = $hmac_method;

$username="mydbusername";

$mySQL=" select * from `healthtokens` where service='WITHINGS' and userid='".$username."'";
$data=mysql_query($mySQL) or die("Died at 2<BR>".mysql_error());

$tokenrow = mysql_fetch_array( $data );

$serviceuserid=$tokenrow['serviceuserid'];
$otoken=$tokenrow['otoken'];
$overifier=$tokenrow['overifier'];

 $acc_tok = new OAuthToken($otoken,$overifier);



$req = OAuthRequest::from_consumer_and_token($consumer, $acc_tok, "GET", "http://wbsapi.withings.net/user?action=getbyuserid&userid=".$serviceuserid);
$req->sign_request($sig_method, $consumer, $acc_tok);


$response = file_get_contents($req);


echo $response;


?>

Withings API 文档: http: //www.withings.com/en/api

我打电话的一个例子:

http://wbsapi.withings.net/user?action=getbyuserid&oauth_consumer_key=mybigconsumerkeyishere&oauth_nonce=f57a956d52c7412326fb0577e87addc4&oauth_signature=jiBNvql5r06HysjjVyxCh7C7ZUk%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1381758029&oauth_token=4088d6173b78b71cfd6ddd4245496de4b1f7b3c45bfb49f8e59b1202ccfc&oauth_version=1.0&userid=1234567

4

1 回答 1

2

我知道这听起来很傻,也让我有些头疼,但是 oauth 1(或至少 withings)的“有趣”之处在于,参数的顺序很重要。

尝试使用 withings oauth 示例 ( http://www.withings.com/en/api/oauthguide )中的 EXACT 顺序:

http://wbsapi.withings.net/measure?
action=getmeas
&oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b
&oauth_nonce=accbac1b7ee2b86b828e6dc4a5a539b2
&oauth_signature=XfobZMboIg2cRyNKAvyzONHHnKM%3D
&oauth_signature_method=HMAC-SHA1
&oauth_timestamp=1311842514
&oauth_token=887557411788d5120537c6550fbf2df68921f8dd6f8c7e7f9b441941eb10
&oauth_version=1.0
&userid=831
于 2013-11-08T12:02:42.937 回答