2016-06-11 109 views
0

如何使用guzzle調用linkedin 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())響應。

希望它有助於其他人陷入同樣的​​問題。