2017-01-16 4 views
0

LaravelとGuzzleを使用してSalesforceからトークンを取得しようとしています。 Postmanを試してみると、ログインは正常に動作します。エンドポイント・コールを試行すると、unsupported_grant_typeエラーが発生します。Laravel、Guzzle、Salesforce - サポートされていないグラントタイプ

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); 
    } 
+0

がつがつ食うのバージョンは何? – Kyslik

+0

バージョン6.2が引き込まれました。 – Zamereon

+0

Guzzle 6+のドキュメントを読んだことがありますか? – Kyslik

答えて

1

このエラーメッセージは、主に、彼らはあなたの要求で「grant_type」パラメータが見つからなかったことを意味します

は、ここに私のコードです。

Psr7 \ Request、3番目のパラメータヘッダーでリクエストを作成しているようです。したがって、パラメータをヘッダとして送信しています。

チェックこの例:

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' 
      ] 
     ] 
    ); 

}

+0

これはうまくいきました。ありがとう! – Zamereon

関連する問題