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

调用LinkedIn Voyager API发起GET请求返回400 INKApi错误求助

LinkedIn Voyager API 400 INKApi 错误排查与修复

问题复现

调用LinkedIn内部Voyager接口尝试拉取用户资料、feed动态、帖子、聊天消息等数据时,使用如下代码发起请求,抛出400客户端错误:

import json 
import requests


# URL = "https://www.linkedin.com/voyager/api/voyagerMessagingDashConversationNudges"
URL = "https://www.linkedin.com/voyager/api/identity/dash/profiles"

cookies = {
   #Cookies are here
}

params = {
    'decorationId': 'com.linkedin.voyager.dash.deco.identity.profile.WebTopCardCore-6',
    'memberIdentity': 'maria-albert-137632240',
    'q': 'memberIdentity',
}

def get_group(url: str, cookies: dict, data:dict, header: dict):
    response = requests.get(url=url, cookies=cookies, data=json.dumps(data), headers=header)
    response.raise_for_status()
    return response.json()

if __name__ == "__main__":
    print("sending request to Server:\n")
    get_group(url=URL, cookies=cookies, data=params, header=headers)

报错信息:

raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: INKApi Error for url: https://www.linkedin.com/voyager/api/identity/dash/profiles

核心错误排查点

  • GET请求参数传递位置错误:这是触发本次400错误的最主要原因。requests库的data参数会把内容放到请求体中发送,仅适用于POST/PUT等带请求体的请求方法;GET请求的查询参数必须通过params关键字传入,库会自动将参数拼接在URL末尾。原代码把查询参数序列化后塞到GET请求体里,LinkedIn接口完全读不到q、memberIdentity这类必填参数,直接触发参数校验失败。
  • 缺失必填请求头,且引用未定义变量:原代码传入的headers变量没有提前定义,就算参数位置传对也会直接抛出NameError。LinkedIn Voyager接口对请求头校验极严,缺失以下任意头都会触发拦截或400错误:
    • csrf-token:值从Cookie中的JSESSIONID字段提取,需要去掉字段值包裹的双引号
    • x-restli-protocol-version:固定值为2.0.0,所有Voyager接口强制校验
    • User-Agent:必须和真实浏览器的UA一致,不能用requests默认的UA标识
    • Accept:固定值为application/vnd.linkedin.normalized+json+2.1,匹配接口返回格式要求
  • 硬编码的接口参数版本过期:代码中写死的decorationId是和LinkedIn前端版本绑定的,平台迭代后旧版本的decorationId会直接失效,触发参数错误。这类参数不要直接抄网上的旧代码,要从自己浏览器登录LinkedIn时的对应网络请求里复制最新值。
  • Cookie有效性问题:如果复制的Cookie缺失li_at核心鉴权字段、已经过期,或者账号触发了平台风控,也会返回400类错误,需要先确认Cookie是从已正常登录的浏览器中最新复制的,账号没有被限制访问。

修复后的参考代码

import requests

URL = "https://www.linkedin.com/voyager/api/identity/dash/profiles"

cookies = {
    # 填入从浏览器控制台复制的完整Cookie,必须包含li_at、JSESSIONID字段
}

# 提取CSRF Token
csrf_token = cookies["JSESSIONID"].replace('"', "")
headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
    "Accept": "application/vnd.linkedin.normalized+json+2.1",
    "x-restli-protocol-version": "2.0.0",
    "csrf-token": csrf_token
}

params = {
    # 建议从浏览器真实请求中复制最新的decorationId,不要硬编码旧值
    'decorationId': 'com.linkedin.voyager.dash.deco.identity.profile.WebTopCardCore-6',
    'memberIdentity': 'maria-albert-137632240',
    'q': 'memberIdentity',
}

def get_profile(url: str, cookies: dict, params: dict, headers: dict):
    # GET请求通过params传递查询参数,不传入data字段
    response = requests.get(url=url, cookies=cookies, params=params, headers=headers)
    response.raise_for_status()
    return response.json()

if __name__ == "__main__":
    print("sending request to Server:\n")
    resp_data = get_profile(url=URL, cookies=cookies, params=params, headers=headers)
    print(resp_data)

其他接口调用注意事项

  • 拉取feed动态、个人发帖、聊天消息等其他Voyager接口的逻辑和个人资料接口一致,所有GET请求的查询参数都通过params传递,不要放到请求体中
  • 所有Voyager接口都必须携带x-restli-protocol-version和csrf-token请求头,缺一不可
  • 控制请求频率,高频请求很容易触发LinkedIn风控,导致Cookie失效甚至账号临时封禁
  • 不同接口的查询参数、decorationId必须和浏览器抓包拿到的最新值一致,LinkedIn前端迭代速度快,网上公开的旧参数通常1-2个月就会失效

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 05:57:12