尝试在linkenin中获取连接时获取错误

时间:2016-11-21 08:06:46

标签: php codeigniter curl linkedin-api

这是我的控制器

<?php

class Linkedin extends CI_Controller 
{
public function __construct ()
{
    parent::__construct();
}

public function login ()
{
    redirect('https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=client_id&redirect_uri=domain');
}

public function index ()
{       
    $state = $_GET['state'];
    if($state == '987654321')
    { 
        $authorization_code = $_GET['code'];
        // Initiating curl
        $curl = curl_init();
        // Here we exchanging 'authorization code' to access token
        // Access token is used to get userdetails
        curl_setopt_array($curl, array(
            CURLOPT_HTTPHEADER      => array('Content-Type: application/x-www-form-urlencoded'),
            CURLOPT_RETURNTRANSFER  => 1,
            CURLOPT_URL             => 'https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code='.$authorization_code.'&client_id=client_id&client_secret=app_secret&redirect_uri=domain',
            CURLOPT_USERAGENT       => 'To get access token',
            CURLOPT_POST            => 1,
            CURLOPT_POSTFIELDS      => array()
        ));
        // Send the request & save response to $resp
        $response = curl_exec($curl);
        $response = json_decode($response);
        curl_close($curl);          
    }
    $curl_req = curl_init();
        curl_setopt_array($curl_req, array(
            CURLOPT_HTTPHEADER      => array('Connection : Keep-Alive','Authorization: Bearer '.$response->access_token.''),
            CURLOPT_RETURNTRANSFER  => 1,
            CURLOPT_URL             => 'http://api.linkedin.com/v1/people/~',
            CURLOPT_USERAGENT       => 'user details',
        ));

        $resp = curl_exec($curl_req);
        echo $resp; 

        curl_close($curl_req);
}
}

我是从源linkedin docs做到的。好吧,除了get_details函数之外,所有似乎都工作正常。我无法获取用户配置文件的详细信息,每次登录后都会返回错误

{ 
    "errorCode": 0, 
    "message": "ssl required",
    "requestId": "HLDS2BCBW4",
    "status": 401,
    "timestamp": 1479715273015
}

1 个答案:

答案 0 :(得分:0)

只需将第CURLOPT_URL => 'http://api.linkedin.com/v1/people/~'行更改为CURLOPT_URL => 'https://api.linkedin.com/v1/people/~?format=json'即可