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

调用LinkedIn AdAccount Users API报错:accounts参数值类型无效

解决LinkedIn API获取广告账户用户的参数类型错误

调用LinkedIn API获取广告账户用户时,返回如下400错误:

[
  "message" => "Invalid value type for parameter accounts",
  "status" => 400
]

使用Laravel Illuminate\Support\Facades\Http 发起请求的原代码:

$response = Http::withHeaders([
               'X-Restli-Protocol-Version' => '2.0.0',
               'LinkedIn-Version' => '202304',
               'Authorization' => 'Bearer xxxxxxxxx',
          ])
           ->baseUrl('https://api.linkedin.com/rest/')
           ->get('adAccountUsers', [
                     'q' => 'accounts', 
                     'accounts' => 'urn:li:sponsoredAccount:509935087'
           ]);

问题原因

accounts 参数的类型不符合API要求:LinkedIn API规定该参数需为数组格式,即使仅传递单个账户URN,也必须用数组包裹。

修复代码

将accounts参数改为数组形式:

$response = Http::withHeaders([
               'X-Restli-Protocol-Version' => '2.0.0',
               'LinkedIn-Version' => '202304',
               'Authorization' => 'Bearer xxxxxxxxx',
          ])
           ->baseUrl('https://api.linkedin.com/rest/')
           ->get('adAccountUsers', [
                     'q' => 'accounts', 
                     'accounts' => ['urn:li:sponsoredAccount:509935087']
           ]);

Laravel的Http门面会自动将数组参数转换为符合LinkedIn RESTli 2.0.0协议的查询字符串格式,API即可正确解析参数类型。

内容的提问来源于stack exchange,提问作者Mina Zakaria

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 05:25:19