Php Laravel、Guzzle和Salesforce-不支持的授权类型

Php Laravel、Guzzle和Salesforce-不支持的授权类型,php,laravel,salesforce,guzzle,guzzle6,Php,Laravel,Salesforce,Guzzle,Guzzle6,我想从Salesforce用Laravel和Guzzle得到一个代币。当尝试通过邮递员,登录工作正常。当我尝试我的端点调用时,我得到一个不受支持的\u grant \u类型错误 这是我的密码: public function login(LoginRequest $request) { $client = new Client(); $salesforce = new Request( 'POST', 'https://test.salesforce.c

我想从Salesforce用Laravel和Guzzle得到一个代币。当尝试通过邮递员,登录工作正常。当我尝试我的端点调用时,我得到一个不受支持的\u grant \u类型错误

这是我的密码:

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);
  }
公共函数登录(LoginRequest$request){
$client=新客户端();
$salesforce=新请求(
"岗位",,
'https://test.salesforce.com/services/oauth2/token',
[
“标题”=>[
“内容类型”=>“应用程序/x-www-form-urlencoded”
],
“表单参数”=>[
“用户名”=>$request->email,
“密码”=>$request->password,
'客户端id'=>'',
“客户机密”=>“”,
'授权类型'=>'密码'
]
]);
$response=$client->send($salesforce);
}

此错误消息主要表示他们在您的请求中未找到“grant\u type”参数

看起来您正在使用Psr7\request,第三个参数-headers创建一个请求。因此,您将参数作为标题发送

检查此示例:

public function login(LoginRequest $request) {
    $client = new Client();

    $response = $client->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'
            ]
        ]
    );
公共函数登录(LoginRequest$request){
$client=新客户端();
$response=$client->request(
"岗位",,
'https://test.salesforce.com/services/oauth2/token',
[
“标题”=>[
“内容类型”=>“应用程序/x-www-form-urlencoded”
],
“表单参数”=>[
“用户名”=>$request->email,
“密码”=>$request->password,
'客户端id'=>'',
“客户机密”=>“”,
'授权类型'=>'密码'
]
]
);

}

Guzzle的哪个版本?6.2版就是其中的一个。你看过Guzzle 6+的文档了吗?是的,这就是我所关注的。我在想可能有一些特定的授权类型,但我没有看到任何东西。如果请求是Psr7\请求,您应该将头和正文分开放置。新请求('POST'、'…'、$headers、$body);