I am trying getting access token no i'm getting this error
{"error_description":"The authorization grant type is not supported by the authorization server","error":"unsupported_grant_type"}
$code = $_GET['code'];
$postfields = array(
'grant_type'=>'authorization_code',
'code'=>$code,
'redirect_uri='=>'example/myTest.php',
'client_id'=>'amzn1.application-oa2-client.xxxxxxxxxxx',
'client_secret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.amazon.com/auth/o2/token');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($httpRequest, CURLOPT_HEADER, 1);
// Edit: prior variable $postFields should be $postfields;
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // On dev server only!
$result = curl_exec($ch);
print_r($result);
Change CURLOPT_HTTPHEADER
from
Content-Type: application/x-www-form-urlencoded
to
Content-Type: application/json
Try to add 'token_type' => 'bearer'
to your $postfields
data.
Here is from Amazon developer documentation: "Access Token Request ... The type of token returned. Should be bearer."
"Access Token Response: ... unsupported_grant_type The client specified the wrong token_type."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With