LinkedIn OAuth a required parameter “clien_id” is missing

核能气质少年 提交于 2019-12-22 07:21:53

问题


Hi guys i'm working with the LinkedIn API and trying to make request but when I try to get my accesstoken i'm getting the following error in my json print:

Array ( [error] => missing_parameter [error_description] => A required parameter "client_id" is missing )

this is my code:

<?php

    $url = parse_url("https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
    parse_str($url['query'], $url);

    $code = $url['code'];

    $data = array("grant_type" => "authorization_code", 
                  "code" => $code,
                  "redirect_uri" => "REDIRECT_URI",
                  "client_id" => "SECRET",
                  "client_secret" => "SECRET"
              );

    $url2 = "https://www.linkedin.com/oauth/v2/accessToken";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_URL, $url2);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
    curl_close($curl);

    $result_array = json_decode($result, true);

    print_r($result_array);

    include('../twitter/navigatie.php');

    echo '<div class="container">';

    echo '';

    echo '</div>';

?>

回答1:


I found the problem

it needed to be in a string.

so this:

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

became this:

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));

Curl or LinkedIn seemed kinda sensitive for it.



来源:https://stackoverflow.com/questions/39369757/linkedin-oauth-a-required-parameter-clien-id-is-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!