php - Withings API 未重定向到我的回调 URL (PHP/OAuth)

标签 php api oauth withings

我正在遵循提供的指南 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/

相关文章:

security - OAuth 1.0a,2 足 : how do you securely store clients' credentials (keys/secrets)?

api - 如何验证oauth签名或请求?

php - SQL : update multiple rows in php frontend

php - 执行 PHP 端锁定时如何选择锁定名称

php - PHP 代码 : header() in Asp.Net 的等价物是什么?

php - 如何使用 API 添加条目到 mysql 数据库?

Android:如何以编程方式检查 WhatsApp 上的号码是否在线?

oauth - OAuth 1.0 领域代表什么?

php - Select 语句回显行两次

php - Google Analytics 数据导出 API V3