首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从amazon获取“授权服务器不支持授权授权类型”

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

Stack Overflow用户
提问于 2016-11-15 17:22:34
回答 3查看 7.1K关注 0票数 5

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

{“error”:“授权服务器不支持授权授权类型”,“error_description”:“unsupported_grant_type”}

代码语言:javascript
运行
复制
$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);
EN

回答 3

Stack Overflow用户

发布于 2018-01-09 17:54:27

CURLOPT_HTTPHEADER更改为

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

Content-Type: application/json

票数 4
EN

Stack Overflow用户

发布于 2016-11-15 17:32:32

尝试向您的$postfields数据添加'token_type' => 'bearer'

下面是来自Amazon开发人员文档的内容:“访问令牌请求...返回的令牌的类型。应该是承载的。”

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

票数 1
EN

Stack Overflow用户

发布于 2021-10-08 01:19:09

这是一个很老的问题,但是在official documentation中,它说有效的值是refresh_tokenclient_credentials

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40606147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档