尝试在 linkedin 中获取连接数时出错
Getting error while try to get connections count in linkenin
这是我的控制器
<?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 function.I 无法获取用户个人资料详细信息外,一切似乎都正常,每当我在登录
后尝试时都会出现 returns 错误
{
"errorCode": 0,
"message": "ssl required",
"requestId": "HLDS2BCBW4",
"status": 401,
"timestamp": 1479715273015
}
刚刚将行 CURLOPT_URL => 'http://api.linkedin.com/v1/people/~'
更改为 CURLOPT_URL => 'https://api.linkedin.com/v1/people/~?format=json'
并且有效
这是我的控制器
<?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 function.I 无法获取用户个人资料详细信息外,一切似乎都正常,每当我在登录
后尝试时都会出现 returns 错误{
"errorCode": 0,
"message": "ssl required",
"requestId": "HLDS2BCBW4",
"status": 401,
"timestamp": 1479715273015
}
刚刚将行 CURLOPT_URL => 'http://api.linkedin.com/v1/people/~'
更改为 CURLOPT_URL => 'https://api.linkedin.com/v1/people/~?format=json'
并且有效