<?php
$client_id = "239";
$client_secret = "dbd8a92f126ed1a874218f17329f9432688769b2";
$access_token = "0cd76192710efdd76818141513659835b61a188e";
$redirect_uri = "http://localhost/";
$response_type = "code";
$scope = "";
$approval_prompt = "";
function authorizeUrl($clientId, $response_type, $redirect_uri, $scope, $approval_prompt){
$authorizeUrl = "https://www.strava.com/oauth/authorize?client_id=$clientId&response_type=$response_type&redirect_uri=$redirect_uri&scope=$scope&approval_prompt=$approval_prompt";
return $authorizeUrl;
}
function parseJason ($response){
return json_decode($response);
}
function tokenRequest($clientId, $clientSecret, $code){
$oauthFields = array(
'client_id' => $clientId,
"client_secret" => $clientSecret,
"code" => $code);
var_dump($oauthFields);
echo "<br>";
echo "<br>" . $oauthFields . "<br>";
print_r($oauthFields);
$oauthFieldsObject = (object) $oauthFields;
echo "<br>";
var_dump($oauthFieldsObject);
echo "<br>";
print_r($oauthFieldsObject);
echo "<br>";
$parameters = '&' . http_build_query($oauthFields);
var_dump($parameters);
echo "<br>". $parameters;
echo "<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.strava.com/oauth/token?");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
var_dump($ch);
$urlResponse = curl_exec($ch);
echo "<br>";
var_dump($urlResponse);
$http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$http_decoded = json_decode($http_response);
echo "<br>" . $http_decoded;
curl_close($ch);
return json_decode($urlResponse);
}
echo $client_secret;
echo "<br>";
$loginUrl = authorizeUrl($client_id,$response_type,$redirect_uri, $scope, $approval_prompt);
echo "<a href='$loginUrl'>Click here<a>". "<br>" ;
echo $loginUrl ."<br>";
echo 'https://www.strava.com/oauth/authorize?client_id=239&response_type=code&redirect_uri=http://localhost&approval_prompt=force'."<br>";
$codeUrl = null;
if (isset($_GET['code'])){
$codeUrl = $_GET['code'];
}
else {
echo "<a href='$loginUrl'>Click here<a>". "<br>" ;
}
echo $codeUrl;
$buildOauthTokenExchange = "https://wwww.strava.com/oauth/token";
echo "<br>";
$token = tokenRequest($client_id, $client_secret, $codeUrl);
echo "<br>";
var_dump($token);
?>
preferences:
49.76 ms | 402 KiB | 5 Q