Can't manage to get access token from linkedin api with oauth v2.0

i've been following this guide and as it mentions I did the following request to get the access_token using php 7.1.7 and curl

function httpRequest($url, $auth_header, $method, $body = NULL){

    if (!$method){$method = "GET";}
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers.

    if ($body) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
    }
    $data = curl_exec($curl);
    curl_close($curl);
    return $data;
}

Then I make the POST request like this:

$post_data = httpRequest("www.linkedin.com/oauth/v2/accessToken",$auth_header, "POST", $body);

where

$auth_header = null;
$code = $_GET['code'];
$body = "grant_type=authorization_code&code=".$code."&redirect_uri=".$config['callback_url']."&client_id=".$config['linkedin_access']."&client_secret=".$config['linkedin_secret'];

I know that I'm getting the authorization code correctly but for some reason I'm not able to get

access_token

neither

expires_in

instead, I'm getting the following error

{"error":"https_required","error_description":"The client is not authorized"}

Thanks in advance.


我发现你必须使用https://www.linkedin.com/oauth/v2/accessToken,而不是简单的www.linkedin.com/oauth/v2/accessToken

链接地址: http://www.djcxy.com/p/68442.html

上一篇: 在Scala中读取整个文件?

下一篇: 使用oauth v2.0无法管理从linkedin api获取访问令牌