Question:
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”}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$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); |
Answer:
Change CURLOPT_HTTPHEADER
from
Content-Type: application/x-www-form-urlencoded
to
Content-Type: application/json