微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 从亚马逊获取“授权服务器不支持授权授权类型”

我正在尝试获取访问令牌没有我收到此错误

{“error_description”:“授权服务器不支持授权授权类型”,“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);

解决方法:

尝试添加’token_type’=>你的$postfields数据的’bearer’.

这是来自亚马逊的开发者文档:
“访问令牌请求…返回的令牌类型.应该是持票人.”

“访问令牌响应:… unsupported_grant_type客户端指定了错误的token_type.”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐