无法使用 oauth v2.0 从 linkedin api 获取访问令牌

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

我一直在关注这个 guide 并且正如它提到的那样,我做了以下请求以使用 php 7.1.7 和 curl

获得 access_token
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;
}

然后我这样 POST 请求:

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

哪里

$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'];

我知道我正在正确获取授权码,但由于某些原因我无法获取

access_token

都没有

expires_in

相反,我收到以下错误

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

提前致谢。

我发现您必须使用 https://www.linkedin.com/oauth/v2/accessToken 而不是简单地 www.linkedin。com/oauth/v2/accessToken