You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LinkedIn introspectToken验证token失败:提示缺少client_id

解决LinkedIn introspectToken接口"client_id缺失"问题
  • 核心问题:你把client_id、client_secret、token放在了URL查询参数里,但LinkedIn的introspectToken接口要求这些参数通过POST请求体以application/x-www-form-urlencoded格式传递,而非URL参数。

  • 错误做法示例(你当前的写法):

$url = 'https://api.linkedin.com/v2/introspectToken?client_id=XXX&client_secret=YYY&token=ZZZ';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
// ...其他设置
curl_exec($ch);
  • 正确做法:将参数组装成表单字符串,通过CURLOPT_POSTFIELDS传递到请求体:
$url = 'https://api.linkedin.com/v2/introspectToken';
$postData = http_build_query([
    'client_id' => '你的客户端ID',
    'client_secret' => '你的客户端密钥',
    'token' => '要验证的access_token'
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// 处理响应
if ($httpCode === 200) {
    $result = json_decode($response, true);
    // 根据result中的active字段判断token是否有效
    var_dump($result['active']);
} else {
    echo "请求失败: " . $response;
}
  • 为什么命令行curl能成功?
    因为你用命令行时应该是用了-d参数(比如curl -X POST -d "client_id=XXX&client_secret=YYY&token=ZZZ" https://api.linkedin.com/v2/introspectToken),-d参数会自动把数据放到POST请求体里,同时默认添加Content-Type: application/x-www-form-urlencoded头,完全符合接口要求。

内容的提问来源于stack exchange,提问作者Andy Wallace

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.02 06:13:16