Withings API不是重定向到我的回调URL(PHP / OAuth的) [英] Withings API not redirecting to my callback url (PHP / OAuth)

查看:157
本文介绍了Withings API不是重定向到我的回调URL(PHP / OAuth的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面提供这里为了得到一个永久访问指南Withings通过OAuth协议帐户。一切完美,直到第二个步骤的最后一部分:


  

授权此令牌:结果
  ......然后,用户可以通过点击
  允许按钮,他将被重定向到您设置的回调URL
  在此步骤的开始。 ...


然而,当用户点击允许,我不是重定向到我的回调URL。相反,我定向到一个访问授予Withings页与组oauth_token和oauth_verifier。

请帮忙?

他们表现出以下的例子:

 > 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 code:

  $ callback_uri = rawurlen code(http://www.mysite.com);
$ authorization_uri =
https://oauth.withings.com/account/authorize~~V? 。
oauth_callback ='。 $ callback_uri。
'和; oauth_consumer_key ='。 $ oauth_params ['oauth_consumer_key']。
'和; oauth_nonce ='。 $ oauth_params ['oauth_nonce']。
'和; oauth_signature ='。 rawurlen code($ oauth_signature)。
'和; oauth_signature_method ='。 $ oauth_params ['oauth_signature_method']。
'和; oauth_timestamp ='。 $ oauth_params ['oauth_timestamp']。
'和;' 。 $令牌。
'和; oauth_version ='。 $ oauth_params ['oauth_version'];标题(位置:$ authorization_uri);


解决方案

哇... ok了。我终于得到了这一点。我花了一段时间才能弄明白。

显然,必须在请求令牌的步骤(步骤1)和未授权步骤(步骤2)被设置在回调URL。因此,高于一切仍然是正确事情是这样的。

I'm following the guide provided here in order to get permanent access to a Withings account via the OAuth protocol. Everything works perfectly until the last part of the second step:

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. ...

However, when the user hits Allow, I am not redirected to my callback url. Instead, I am directed to an "Access Granted" Withings page with an oauth_token and an oauth_verifier.

Please help?

The example they have show the following:

> 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

While my call looks like this:

> 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

This is my php code:

$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);

解决方案

Wow... ok. I finally got this. Took me a while to figure it out.

Apparently, the callback url must be provided at the request Token step (step 1) and not the Authorization step (step 2). So everything above is still correct the way it is.

这篇关于Withings API不是重定向到我的回调URL(PHP / OAuth的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆