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

Laravel HTTP Client调用LinkedIn认证提示grant_type参数缺失

解决Laravel HTTP Client请求LinkedIn Access Token报错问题

你的问题出在表单参数的传递方式上:Laravel的Http::asForm()方法已经将请求设置为application/x-www-form-urlencoded格式,此时POST请求的第二个参数直接传字段数组即可,不需要嵌套form_params键。

你当前的写法会把form_params作为一个单独的表单字段发送,导致LinkedIn完全接收不到grant_type、client_id这些必填参数,所以才返回"grant_type缺失"的错误。

修正后的代码

$response = Http::asForm()->post("https://www.linkedin.com/oauth/v2/accessToken", [
    'client_id' => config('services.linkedin.client_id'),
    'client_secret' => config('services.linkedin.client_secret'),
    'grant_type' => 'client_credentials'
])->json();

额外验证要点

  • 确认config/services.php里的linkedin配置项正确填写了client_id和client_secret
  • 检查LinkedIn开发者后台的应用是否启用了client_credentials授权类型
  • 确保请求地址无误(你当前的地址是正确的LinkedIn OAuth2令牌端点)

内容的提问来源于stack exchange,提问作者Tomas C. Lopes

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 02:50:32