我正在尝试使用linkedin API为请求令牌交换auth代码。但是我试着总是收到错误:
{[“error_description”] => string(107)“缺少必需的参数, 包含无效参数值,参数不止一次。 : client_secret“[”error“] => string(15)”invalid_request“}
我的代码如下:
public function authorization($authCode)
{
//define enviroment and path
$host = "https://www.linkedin.com/uas/oauth2/accessToken";
// Generate urlencode data
$data_string = 'grant_type=authorization_code';
$data_string .= '&code='.$authCode;
$data_string .= '&redirect_uri='.redirectUrl;
$data_string .= '&client_id='.publicKey;
$data_string .= '&client_secret'.secretKey;
var_dump($data_string);
// set up the curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
));
// execute the request
$output = curl_exec($ch);
//echo($output) . PHP_EOL;
$output = json_decode($output);
var_dump($output);
echo $output->access_token;
// close curl resource to free up system resources
curl_close($ch);
}
简单的函数调用就像:
if(!empty($_GET['code']))
{
$state = $_GET['state'];
$authCode = $_GET['code'];
$LinkedIn->authorization($authCode);
}
我尝试通过postman使用我的数据进行此请求,并且我成功获得了Access令牌,所以我在这里有一些我看不到的错误。
有谁能告诉我我做错了什么? 感谢
答案 0 :(得分:3)
我认为你需要等同于'在client_secret之后签名
<script>
var currentx = 0,
viewport = 1920;
$(window).keydown(function (e) {
var btnright = (+currentx) + (+viewport),
btnleft = (+currentx) - (-viewport);
if ( e.which == 37 ) {
window.scrollTo(btnleft, 0);
currentx = (+currentx) - (-viewport);
} else if ( e.which == 39 ) {
window.scrollTo(btnright, 0);
currentx = (+currentx) + (+viewport);
}
});
</script>