1

也许有人可以帮助我,我正在尝试在我的应用程序首次授权运动员后发布刷新令牌,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 的代码:

<?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 脚本中......

谢谢帮助。

4

1 回答 1

2

终于找到了解决方案,它是一个范围参数,我提供了一个错误的范围,并且带有scope=read_all&scope=activity:read_all, it works perfectly.

于 2018-10-27T18:30:54.213 回答