2016-11-21 42 views
0

這裏是我的控制器得到錯誤,同時試圖讓連接計數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做工精細不能得到用戶配置文件的詳細信息,每當我登錄後嘗試

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

'401'手段[未經授權](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)和'ssl required'意味着您的服務器頁面必須提供'https'安全連接。近幾年來,像linkedin,Google等公司需要在他們的服務器和服務器之間建立「https」連接是非常常見的。 – Tpojka

+1

Thakns尋求幫助@Tpojka。正如你所說,我已將'CURLOPT_URL =>'http:// api.linkedin.com/v1/people /〜''這一行更改爲'CURLOPT_URL =>'https://api.linkedin.com/v1/people /〜?format = json'',它的工作原理。 –

回答

0

只是改了行CURLOPT_URL => 'http://api.linkedin.com/v1/people/~'CURLOPT_URL => 'https://api.linkedin.com/v1/people/~?format=json'返回錯誤和它的作品

相關問題