php 从amazon获取“授权服务器不支持该授权类型”

wljmcqd8  于 2023-02-18  发布在  PHP
关注(0)|答案(3)|浏览(141)

我正在尝试获取访问令牌,但收到此错误
{“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);
yftpprvb

yftpprvb1#

CURLOPT_HTTPHEADER
Content-Type: application/x-www-form-urlencoded

Content-Type: application/json

kadbb459

kadbb4592#

尝试将'token_type' => 'bearer'添加到$postfields数据中。
以下是Amazon开发人员文档:“访问令牌请求...返回的令牌类型。应该是持有者。”
“访问令牌响应:... unsupported_grant_type客户端指定了错误的令牌类型。”

hl0ma9xz

hl0ma9xz3#

这确实是个老问题,但在官方文档中,有效值是refresh_tokenclient_credentials

相关问题