user3101337
user3101337

Reputation: 364

Strava API, can't get token exchange working

I am able to get an authorized code, but then I can't get the token exchange to work. The response I get is NULL.

Anyone have any insight on this, I've been messing with it for hours.

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";}

Upvotes: 0

Views: 841

Answers (1)

user3101337
user3101337

Reputation: 364

So after looking at the error message (Thanks Kevin), I have changed the CURL_SSL_VERIFYPEER option from TRUE to FALSE. That line of code now looks like this:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

Should also note that I am using XAMPP, should anyone else run into this problem.

Upvotes: 1

Related Questions