Php Linkedin-交换请求令牌的授权代码
我正在尝试使用linkedin API交换请求令牌的身份验证代码。然而,我尝试我总是得到错误: {[“错误描述”]=>字符串(107)“缺少必需的参数, 包含无效的参数值,参数不止一次: 客户端密码“[“错误”]=>字符串(15)“无效的\u请求”} 我的代码如下所示:Php Linkedin-交换请求令牌的授权代码,php,api,linkedin,Php,Api,Linkedin,我正在尝试使用linkedin API交换请求令牌的身份验证代码。然而,我尝试我总是得到错误: {[“错误描述”]=>字符串(107)“缺少必需的参数, 包含无效的参数值,参数不止一次: 客户端密码“[“错误”]=>字符串(15)“无效的\u请求”} 我的代码如下所示: public function authorization($authCode) { //define enviroment and path $host = "https://www.
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);
}
我试图通过邮递员使用我的数据提出这个请求,并且我成功地获得了访问令牌,所以我这里有一些我看不到的错误
有人能告诉我我做错了什么吗?
谢谢我想你需要在客户机密后加一个“等于”的符号
$data_string .= '&client_id='.publicKey;
$data_string .= '&client_secret='.secretKey;
var_dump($data_string);
在变量名前加一个
$
,否则它们将被解释为constantsHi Federico它们是常量这没关系,但是我觉得错过“等于”这个词真的很难受。谢谢@littlebexit,我仍在等待计时器让我“接受”这个正确答案