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

调用LinkedIn API获取UGC帖子统计时出现500内部服务器错误求助

LinkedIn organizationalEntityShareStatistics接口指定UGC帖子时返回500错误

问题概述

调用LinkedIn的organizationalEntityShareStatistics接口时,不指定ugcPosts参数可正常获取组织终身统计数据;但通过URN指定具体UGC帖子后,接口返回500内部服务器错误。已提交官方支持工单未获有效帮助,使用API版本为202408,相关代码如下:

url = "https://api.linkedin.com/rest/organizationalEntityShareStatistics"

params = {
    "q": "organizationalEntity",
    "organizationalEntity": organization_id,
    "ugcPosts": "urn:li:ugcPost:"
}

headers = {
    'Authorization': f'Bearer {linkedin_api_accesstoken}',
    'Linkedin-Version': version,
    'X-Restli-Protocol-Version': '2.0.0'
}

# Make the GET request
response = requests.get(url, headers=headers, params=params)

# Check the response status code and print the response
if response.status_code == 200:
    print("Success:", response.json())
else:
    print("Error:", response.status_code, response.text)

排查方向与解决方案

1. 验证UGC Post URN的有效性

代码中ugcPosts参数值为不完整的"urn:li:ugcPost:",正确格式应为urn:li:ugcPost:{具体帖子ID}(例如urn:li:ugcPost:7123456789012345678):

  • 确认传入完整且有效的帖子URN,无效格式会触发服务器解析错误;
  • 验证该帖子归属目标组织,跨组织查询可能引发异常。

2. 检查参数传递格式

ugcPosts支持多URN逗号分隔(如urn:li:ugcPost:123,urn:li:ugcPost:456):

  • 移除参数中的多余空格或特殊字符,避免服务器解析失败;
  • 先测试单个有效URN,排除多参数传递的格式问题。

3. 排查API版本兼容性

当前使用202408版本API:

  • 尝试降级至前一稳定版本(如202407)测试,排查版本适配问题;
  • 查阅LinkedIn API变更日志,确认202408版本对该接口的未公开调整。

4. 确认请求头配置

  • 确保Linkedin-Version变量值准确设置为202408;
  • 保持X-Restli-Protocol-Version为2.0.0,协议版本不匹配可能引发非预期错误。

5. 获取详细错误信息

修改代码打印完整响应内容,定位具体错误原因:

else:
    print("Error Status Code:", response.status_code)
    print("Response Headers:", dict(response.headers))
    print("Response Text:", response.text)

500错误响应通常包含具体错误码或描述(如INVALID_URN),可进一步缩小排查范围。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 02:00:09