首次授权后未发出Strava API刷新令牌

时间:2018-10-26 13:10:57

标签: php api oauth-2.0 refresh-token strava

也许有人可以帮助我, 我正在尝试在获得运动员的首次授权后发布刷新令牌, Oauth 2.0在邮递员中可以正常工作,并且我可以通过这种方式获取刷新令牌,但在我的过时的php脚本中却无法……我只得到了这种JSON响应:

{
  "token_type": "Bearer",
  "access_token": "ACCESS_TOKEN",
  "athlete": {
    #{summary athlete representation}
  }
}

但是我正在等待刷新令牌和到期日期,如本示例中的Strava API文档所示:

{
  "token_type": "Bearer",
  "access_token": "987654321234567898765432123456789",
  "athlete": {
    #{summary athlete representation}
  }
  "refresh_token": "1234567898765432112345678987654321",
  "expires_at": 1531378346,
  "state": "STRAVA"
}

我试图多次从测试帐户撤消对应用程序的访问权限,以模拟新的身份验证请求,但是我找不到答案,这是他的代码来调用令牌交换URL: / p>

<?php 
require 'config.php';
$code = $_GET['code'];


//The url you wish to send the POST request to
$url = "https://www.strava.com/oauth/token";

//The data you want to send via POST
$fields = [
    'client_id'      => $client_ID,
    'client_secret' => $client_secret,
    'code'         => $code,
    'grant_type' => 'authorization_code'
];

//url-ify the data for the POST
$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

//execute post
$result = curl_exec($ch);
echo $result;
print_r(curl_error($ch))
?>

PS:Oauth 2.0在邮递员中可以正常工作,我可以通过这种方式获取刷新令牌,但在我的常人php脚本中却无法...

谢谢。

1 个答案:

答案 0 :(得分:2)

最后找到了解决方案,它是一个范围参数,我提供了错误的范围,并且使用scope=read_all&scope=activity:read_all, it works perfectly