如何使用 linkedin 和 guzzle?
How to use linkedin and guzzle?
如何使用 guzzle 调用 linkedin api?到目前为止我已经试过了
$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 和 guzzle 6.2。
愚蠢的错误只是将 $client->request('POST',
从 POST
更改为 GET
所以它会是:
$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())
使其可读。
希望对遇到同样问题的其他人有所帮助。
如何使用 guzzle 调用 linkedin api?到目前为止我已经试过了
$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 和 guzzle 6.2。
愚蠢的错误只是将 $client->request('POST',
从 POST
更改为 GET
所以它会是:
$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())
使其可读。
希望对遇到同样问题的其他人有所帮助。