我正在尝试按照使用Guzzle的文档获取 Sage One API 的访问令牌 (v6) / Laravel 5.2(Laravel 的参与与此问题无关),它停留在“请求访问令牌”阶段。
错误
Client error: `POST https://api.sageone.com/oauth2/token` resulted in a
`400 Bad Request` response: {"error":"unsupported_grant_type"}
Run Code Online (Sandbox Code Playgroud)
违规代码
$client = new Client([
'base_uri'=>'https://api.sageone.com',
'headers' => ['content_type' => 'application/x-www-form-urlencoded']
]);
$data = [
'client_id' => getenv('SAGE_CLIENT'),
'client_secret' => getenv('SAGE_SECRET'),
'code' => $request->code,
'grant_type' => 'authorization_code',
'redirect_uri'=>'https://myurl.com/sage/refresh'
];
$response = $client->request('POST','/oauth2/token',['json' => $data]);
Run Code Online (Sandbox Code Playgroud)
文档说明“grant_type - 代码相关的授权类型。authorization_code 或 refresh_token。” ,我两个都试过了。其他 vars 都很好,很花哨,只是grant_type似乎失败了。
更新 1 调试头生成下面的输出。
* Hostname in DNS cache …Run Code Online (Sandbox Code Playgroud)