2016-06-11 8 views
0

グランジを使用してリンクされたAPIを呼び出すにはどうすればよいですか?これまでのところ私はlinkedinとguzzleのインストール方法?

$client = new \GuzzleHttp\Client(['base_uri' => 'https://api.linkedin.com']); 
    $access_token = 'the_access_token'; 
    $req = $client->request('POST', '/v1/people/~?format=json', [ 
      'headers'  => ["Authorization" => "Bearer " . $access_token, 
      "Content-Type" => "application/json", "x-li-format"=>"json"], 
      'client_id'  => 'the_client_id', 
      'client_secret' => 'the_client_secret', 
      'connection' => 'Keep-Alive' 
     ]); 
    dd($req); 

を試してみたんだけど、読み込みエラーが出る:

Client error: POST https://api.linkedin.com/v1/people/~?format=json resulted in a 405 

イムをlaravel 5.1で作業をし、6.2をがつがつ食います。

答えて

0

愚かな間違いは、単にので、それは次のようになりPOSTGETから$client->request('POST',を変更する必要がありました:

$client = new \GuzzleHttp\Client(['base_uri' => 'https://api.linkedin.com']); 
    $access_token = 'the_access_token'; 
    $req = $client->request('GET', '/v1/people/~?format=json', [ 
      'headers'  => ["Authorization" => "Bearer " . $access_token, 
      "Content-Type" => "application/json", "x-li-format"=>"json"], 
      'client_id'  => 'the_client_id', 
      'client_secret' => 'the_client_secret', 
      'connection' => 'Keep-Alive' 
     ]); 
    dd($req); 

は私もjson_decode($request->getBody())を使用して、それが読みやすくなり、応答をデコード。

他の人が同じ問題を抱えている場合に役立ちます。

関連する問題