【问题标题】:How to use linkedin and guzzle?如何使用linkedin和guzzle?
【发布时间】:2016-10-12 09:04:22
【问题描述】:

如何使用 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。

【问题讨论】:

    标签: php laravel laravel-5.1 guzzle linkedin-api


    【解决方案1】:

    愚蠢的错误只是将$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()) 解码了使其可读的响应。

    如果其他人遇到同样的问题,希望能有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2017-11-01
      • 2020-04-02
      • 2017-02-22
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      相关资源
      最近更新 更多