2015-07-20 66 views
1

當我嘗試使用LinkedIn API對用戶進行身份驗證時,出現這個奇怪的錯誤。一個var_dump()的數據顯示:LinkedIn API PHP

string(156) "{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : ssl required","error":"invalid_request"}" 

我不知道爲什麼發生這種情況,任何人都可以幫我解決這個問題。

$ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, "https://www.linkedin.com/uas/oauth2/accessToken?"); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     'Content-Type: application/x-www-form-urlencoded', 
    )); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
     'grant_type' => 'authorization_code', 
     'client_id'  => $account['linkedin']['api_key'], 
     'client_secret' => $account['linkedin']['api_secret'], 
     'code'   => $_GET['code'], 
     'redirect_uri' => get_admin_url() . 'admin.php?page=' . self::$accounts_dashboard_page . '&linkedin=authorization&account=' . urlencode($account['id']), 
    )); 

    $response = curl_exec($ch); 
    curl_close($ch); 

    var_dump($response); 

回答

0

我也得到了同樣的錯誤,但我得到它的工作改變發送參數的方式。而不是和我發送他們像一個典型的QUERY_STRING數組。

我的意思是:

curl_setopt($ch, CURLOPT_POSTFIELDS,'grant_type=authorization_code&client_id=XXXXXXX&client_secret=ZZZZZZZ&code=YYYYY&redirect_uri=/path/to/your/redirect/uri') 

我不知道爲什麼,但它的工作對我來說...

0
$url = "https://www.linkedin.com/uas/oauth2/accessToken"; 
$header = array("Content-Type: application/x-www-form-urlencoded"); 

    $data = http_build_query(array(
     "client_id" => {client_id}', 
     "client_secret" => {client_secret}, 
     "redirect_uri" => {redirect_uri}, 
     "grant_type" => "authorization_code", 
     "code" =>$_GET['code'] 
    )); 

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl, CURLOPT_HEADER, 0); 

    if($header !== 0){ 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
    } 

    curl_setopt($curl, CURLOPT_POST, true); 

    if($data !== 0){ 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
    } 

    $response = curl_exec($curl); 

    curl_close($curl); 

    $respo = json_decode($response); 

echo  $accesstoken = $respo->access_token;