我一直在关注这个guide,并且在提到我做了以下请求以使用php 7.1.7和curl
获取access_tokenfunction 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”:“客户端未获得授权”}
提前致谢。
答案 0 :(得分:0)
我发现您必须使用https://www.linkedin.com/oauth/v2/accessToken,而不仅仅是www.linkedin.com/oauth/v2/accessToken