Strava API,无法进行令牌交换
Strava API, can't get token exchange working
我可以获得授权码,但我无法进行令牌交换。我得到的响应是 NULL。
任何人对此有任何见解,我已经弄乱了几个小时。
function tokenRequest($clientId, $clientSecret, $code){
$url = 'https://www.strava.com/oauth/token?';
$oauthFields = array(
'client_id' => $clientId,
'client_secret' => $clientSecret,
'code' => $code);
$parameters = http_build_query($oauthFields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$parameters);
curl_setopt($ch, CURLOPT_POST, count($oauthFields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
$urlResponse = curl_exec($ch);
curl_close($ch);
return (json_decode($urlResponse));
}
if (isset($_GET['code'])){
$code=$_GET['code'];
echo "code is: " . $code . "</br>";
$token = tokenRequest($clientId, $clientSecret, $code);
var_dump($token);
}
else{echo "User denied access request";}
所以在查看错误消息后(感谢 Kevin),我将 CURL_SSL_VERIFYPEER 选项从 TRUE 更改为 FALSE。该行代码现在看起来像这样:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
还应该注意我正在使用XAMPP,其他人应该运行遇到这个问题。
我可以获得授权码,但我无法进行令牌交换。我得到的响应是 NULL。
任何人对此有任何见解,我已经弄乱了几个小时。
function tokenRequest($clientId, $clientSecret, $code){
$url = 'https://www.strava.com/oauth/token?';
$oauthFields = array(
'client_id' => $clientId,
'client_secret' => $clientSecret,
'code' => $code);
$parameters = http_build_query($oauthFields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$parameters);
curl_setopt($ch, CURLOPT_POST, count($oauthFields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
$urlResponse = curl_exec($ch);
curl_close($ch);
return (json_decode($urlResponse));
}
if (isset($_GET['code'])){
$code=$_GET['code'];
echo "code is: " . $code . "</br>";
$token = tokenRequest($clientId, $clientSecret, $code);
var_dump($token);
}
else{echo "User denied access request";}
所以在查看错误消息后(感谢 Kevin),我将 CURL_SSL_VERIFYPEER 选项从 TRUE 更改为 FALSE。该行代码现在看起来像这样:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
还应该注意我正在使用XAMPP,其他人应该运行遇到这个问题。