How can i store access token and refresh token in php variable?


#1

Hi, I wrote the code and received this json response:

{“refresh_token”:“xxx-xx-xx-xx-xx”,“access_token”:“xxxx”,“expires_in”:21600}

but access token is not getting stored on $myrs variable.

Here is the full code :


$cod=$_GET[“code”];

$url=“https://api.hubapi.com/oauth/v1/token?grant_type=authorization_code&client_id=x-x-x-x-x&client_secretxxxx&redirect_uri=https://www.myurl.com&code=”.$cod;

$agent= ‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)’;

$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_HTTPHEADER, [‘Content-Type: application/x-www-form-urlencoded’]);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL,$url);

$result=curl_exec($ch);

$rest= (json_decode($result, true));
$myrs=$rest[“access_token”];


How can i store the access token in a variable ?

Thank you!


#2

Anyone to solve this issue ?