0
我能夠獲得授權代碼,但後來無法讓令牌交換工作。我得到的迴應是NULL。Strava API,無法獲得令牌交換
任何人都有這方面的見解,我已經搞了好幾個小時。
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";}
您是否嘗試過print_r(curl_error($ ch))? – Kevin
我不知道我能做到這一點。錯誤是:「SSL證書問題,請驗證CA證書是否正確。詳細信息:錯誤:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:證書驗證失敗」 – user3101337
嘗試將CURLOPT_SSL_VERIFYPEER設置爲false。看起來他們的SSL證書可能有問題,但我不確定。哦,我看到你做到了;) – Kevin