我正在遵循提供的指南 here为了通过 OAuth 协议(protocol)永久访问 Withings 帐户。一切都很完美,直到第二步的最后一部分:
Authorize this token :
... Then the User allows by clicking on "Allow" button and he will be redirected to the callback url you set at the beginning of this step. ...
但是,当用户点击“允许”时,我不会重定向到我的回调网址。相反,我被定向到带有 oauth_token 和 oauth_verifier 的“已授予访问权限”Withings 页面。
请帮忙?
他们的示例显示以下内容:
> https://oauth.withings.com/account/authorize?
> oauth_callback=http%3A%2F%2Fexample.com%2Fget_access_token
> &oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b
> &oauth_nonce=369f9ceb2f285ac637c9a7e9e98019bd
> &oauth_signature=OR9J9iEl%2F2yGOXP2wk5c2%2BWtYvU%3D
> &oauth_signature_method=HMAC-SHA1
> &oauth_timestamp=1311778988
> &oauth_token=5bb105d2292ff43ec9c0f633fee9033045ed4643e9871b80ce586dc1bf945
> &oauth_version=1.0
虽然我的通话如下所示:
> https://oauth.withings.com/account/authorize?
> oauth_callback=http%3A%2F%2Fmysite.com
> &oauth_consumer_key=myConsumerKey
> &oauth_nonce=1234
> &oauth_signature=6mQ5iICsxxJyunjrGlZLMFNbUQA%3D
> &oauth_signature_method=HMAC-SHA1
> &oauth_timestamp=1376934855
> &oauth_token=myOauthToken
> &oauth_version=1.0
这是我的 php 代码:
$callback_uri = rawurlencode("http://www.mysite.com");
$authorization_uri =
"https://oauth.withings.com/account/authorize?" .
'oauth_callback=' . $callback_uri .
'&oauth_consumer_key=' . $oauth_params['oauth_consumer_key'] .
'&oauth_nonce=' . $oauth_params['oauth_nonce'] .
'&oauth_signature=' . rawurlencode($oauth_signature) .
'&oauth_signature_method=' . $oauth_params['oauth_signature_method'] .
'&oauth_timestamp=' . $oauth_params['oauth_timestamp'] .
'&' . $token .
'&oauth_version=' . $oauth_params['oauth_version'];
header("Location: " . $authorization_uri);
最佳答案
哇...好吧。我终于明白了。我花了一段时间才弄清楚。
显然,回调 URL 必须在请求 token 步骤(步骤 1)而不是授权步骤(步骤 2)中提供。所以上面的一切仍然是正确的。
关于php - Withings API 未重定向到我的回调 URL (PHP/OAuth),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18320618/