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

我一直在遵循这个指南,因为它提到我做了下面的请求,以获得access_token使用PHP 7.1.7和卷曲

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

也不

过期日期在

相反,我收到以下错误

{“error”:“https_required”,“error_description”:“客户端未被授权”}

提前致谢。


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

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

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

下一篇: Missing parameters when requesting OAUTH token survey monkey v3