M. Deepak M. Deepak - 12 days ago 4
PHP Question

Getting error while try to get connections count in linkenin

Here is my controller

<?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);
}
}


I did this from source linkedin docs . Well all seems working fine except the get_details function.I cannot get the user profile details,it returns error whenever I try after login

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

Answer

Just changed the line CURLOPT_URL => 'http://api.linkedin.com/v1/people/~' to CURLOPT_URL => 'https://api.linkedin.com/v1/people/~?format=json' and it works

Comments