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

LinkedIn评论API调用报错:路径变量语法异常求助

LinkedIn Comments API 路径变量语法异常问题排查

核心原因

你遇到的「Syntax exception in path variables」错误,本质是URL路径中的URN未做URL编码。LinkedIn API要求路径里的特殊字符(比如URN中的冒号:)必须经过编码,直接拼接未编码的URN会导致API解析路径时出现语法错误。

解决方案

在拼接URL时,对$postId进行URL编码,使用PHP的rawurlencode()函数处理即可:

$res = Http::withHeaders([
    "LinkedIn-Version" => "202301",
    "X-Restli-Protocol-Version" => "2.0.0",
])
->withToken($post->account->bearer_token)
->post(
    sprintf(
        env("LINKEDIN_API")."socialActions/%s/comments",
        rawurlencode($postId) // 对路径中的URN做URL编码
    ),
    [
        "actor" => $post->account->account_id,
        "object" => $postId, // 请求体里的object无需编码,保留原始URN格式即可
        "message" => [
            "text" => $post->linkedin_first_comment,
        ],
    ]
);

验证点

编码后的请求URL路径部分应变为:
socialActions/urn%3Ali%3Ashare%3A7037368272257712128/comments

额外检查

如果编码后仍报错,确认actor字段的值是否为正确的URN格式(比如urn:li:person:xxxxxx),LinkedIn API要求actor必须是代表用户或组织的标准URN。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 21:43:19