【发布时间】:2017-05-31 17:02:21
【问题描述】:
我正在尝试使用 Laravel 和 Guzzle 从 Salesforce 获取令牌。尝试通过 Postman 时,登录工作正常。当我尝试端点调用时,我收到了 unsupported_grant_type 错误。
这是我的代码:
public function login(LoginRequest $request) {
$client = new Client();
$salesforce = new Request(
'POST',
'https://test.salesforce.com/services/oauth2/token',
[
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded'
],
'form_params' => [
'username' => $request->email,
'password' => $request->password,
'client_id' => '<super_secret_id>',
'client_secret' => '<super_secret_secret>',
'grant_type' => 'password'
]
]);
$response = $client->send($salesforce);
}
【问题讨论】:
-
什么版本的 Guzzle?
-
6.2 版是引入的。
-
您是否阅读过 Guzzle 6+ 的文档?
-
是的,这就是我所关注的。我在想也许有一些特定的赠款类型,但我什么也没看到。
-
如果 Request 是 Psr7\Request,你应该把 headers 和 body 分开。新请求('POST', '...', $headers, $body);
标签: php laravel salesforce guzzle guzzle6