I am trying to have access to an API that uses OAuth : https://developer.atpco.net/api/oauth/gettoken , and I'd like to be able to get my token in JSON form like this :
{ "access_token": "CSX9w8dKQAThqUQYKalJT60ZXZ0fRe39lQu0GSs4ZC449G0F7tsaji", "token_type": "Bearer", "expires_in": 3600, "scope": "resource.WRITE resource.READ" }
I have my client_id and my client_secret. Postman and Python work perfectly and I am able to retrieve the access-token, but I am having trouble replicating these results with PHP. Can you take a look at my code and provide any help please?
I have tried this solution :
<?php
session_start();
$CLIENT_ID = "xxxxxxxxxx";
$CLIENT_SECRET = "xxxxxxxxxxxxxxx";
$CALLBACK = "http://localhost";
function getAccessCode($client_id, $callback, $client_secret, $request_code) {
$curl = curl_init("https://developer.atpco.net/api/oauth/gettoken");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, rawurldecode(http_build_query(array(
'client_id' => $client_id,
'redirect_uri' => $callback,
'client_secret' => $client_secret,
'code' => $request_code,
'grant_type' => 'authorization_code'
))));
$json = json_decode(curl_exec($curl));
return $json->access_token;
sprintf($access_token);
}
but it doesn't seem to find my access-token :/