1

尝试使用 LinkedIn API 对用户进行身份验证时,我遇到了这个奇怪的错误。数据的 var_dump() 显示了这一点:

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);
4

2 回答 2

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')

我不知道为什么,但它对我有用......

于 2016-10-26T14:59:38.273 回答
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;
于 2017-02-15T12:41:24.213 回答