2013-10-14 43 views
0

全部Withings Rest API簽名錯誤API

我有一個應用程序成功地通過Withing的api和OAuth獲得授權。我得到的結果是令牌和驗證者,但是我不能用這些請求 - 我總是收到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

回答

2

我知道這聽起來很愚蠢,它給了我有些頭疼過,但oauth 1(或者至少是atings)的「有趣的」是,參數的順序很重要。

嘗試使用的確切順序作爲withings OAuth的樣品(http://www.withings.com/en/api/oauthguide)中:

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