LinkedIn 评论中的提及无法通过 API 实现

问题描述 投票:0回答:2

尝试提及用户时,会返回错误:API 端点文档

我做什么:

发布https://api.linkedin.com/rest/socialActions/urn%3Ali%3Ashare%3A%7BshareId%7D/comments

请求正文:

{
    "actor": "urn:li:organization:{actorId}",
    "object": "urn:li:share:{shareId}",
    "message": {
        "attributes": [
            {
                "length": 14,
                "start": 0,
                "value": {
                    "com.linkedin.adsexternalapi.social.PersonAttributedEntity": {
                        "person": "urn:li:person:{personId}"
                    }
                }
            }
        ],
        "text": "Mentioned user test message!"
    }
}

回应:

{
    "message": "ERROR :: /message/attributes/0/value/com.linkedin.adsexternalapi.social.PersonAttributedEntity :: unrecognized field found but not allowed\nERROR :: /message/attributes/0/value :: \"com.linkedin.adsexternalapi.social.PersonAttributedEntity\" is not a member type of union",
    "status": 422
}

以类推的方式提出请求。

linkedin-api
2个回答
0
投票

文档似乎有误...

我能够通过使用以下方式获得评论提及:

{
    "actor": "urn:li:organization:{actorId}",
    "object": "urn:li:share:{shareId}",
    "message": {
        "attributes": [
            {
                "length": 14,
                "start": 0,
                "value": {
                    "com.linkedin.common.MemberAttributedEntity": {
                        "person": "urn:li:person:{personId}"
                    }
                }
            }
        ],
        "text": "Mentioned user test message!"
    }
}

我搜索了一些旧文档并解决了这个问题。

值属性为 com.linkedin.common.CompanyAttributedEntity 和 com.linkedin.common.MemberAttributedEntity

更多信息:https://learn.microsoft.com/en-us/linkedin/compliance/integrations/shares/ugc-post-api?tabs=http#mentions-in-ugc-posts

这是我的整个功能:

export const createComment = async (
  accessToken: string,
  postUrn: string,
  commentParams: CommentMutation,
): Promise<string | undefined> => {
  return (
    await axios.post(
      `https://api.linkedin.com/v2/socialActions/${postUrn}/comments`,
      {
        ...commentParams,
      },
      {
        headers: {
          Authorization: `Bearer ${accessToken}`,
          "Content-Type": "application/json",
        },
      },
    )
  ).data;
};


0
投票

如果您使用 linkedin 版本 202307 或更高版本,请按照以下语法进行成功的 API 调用。

使用 person 代替 com.linkedin.common.MemberAttributedEntity 并使用 organization 代替 com.linkedin.common.CompanyAttributedEntity

"actor": "urn:li:organization:{orgId}",
"message": {
    "attributes": [
        {
            "length": 17,
            "start": 0,
            "value": {
                "organization": {
                    "organization": "urn:li:organization:{orgId}"
                }
            }
        },
        {
            "length": 14,
            "start": 38,
            "value": {
                "person": {
                    "person": "urn:li:person:{personId}"
                }
            }
        }
    ],
    "text": "Dunder Mifflin's Dundie Award goes to Dwight Schrute!"
},
"object": "urn:li:share:{shareId}"
© www.soinside.com 2019 - 2024. All rights reserved.