Linkedin - 请求令牌的交换授权码
Linkedin - Exchange Authorization Code for a Request Token
我正在尝试使用 linkedin API 为请求令牌交换授权码。但是我尝试总是出错:
{ ["error_description"]=> string(107) "missing required parameters,
includes an invalid parameter value, parameter more than once. :
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);
}
我尝试通过邮递员使用我的数据发出此请求,并且我成功获得了访问令牌,所以我这里有一些我看不到的错误。
这里有人可以告诉我我做错了什么吗?
谢谢
我认为你需要在 client_secret
之后加上一个 'equal to' 符号
$data_string .= '&client_id='.publicKey;
$data_string .= '&client_secret='.secretKey;
var_dump($data_string);
我正在尝试使用 linkedin API 为请求令牌交换授权码。但是我尝试总是出错:
{ ["error_description"]=> string(107) "missing required parameters, includes an invalid parameter value, parameter more than once. : 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);
}
我尝试通过邮递员使用我的数据发出此请求,并且我成功获得了访问令牌,所以我这里有一些我看不到的错误。
这里有人可以告诉我我做错了什么吗? 谢谢
我认为你需要在 client_secret
之后加上一个 'equal to' 符号$data_string .= '&client_id='.publicKey;
$data_string .= '&client_secret='.secretKey;
var_dump($data_string);