LinkedIn API评论@提及功能202307版本失效问题求助
LinkedIn API 202307+版本评论@提及功能适配方案
问题背景
此前在LinkedIn API 202306版本中,我们通过未公开的com.linkedin.common.MemberAttributedEntity字段实现评论@提及功能,对应属性结构如下:
"attributes": [ { "length": 25, "start": 0, "value": { "com.linkedin.common.MemberAttributedEntity": { "member": "urn:li:person:ARUhKQtm5a" } } } ]
但升级至202307及后续版本后,该方式返回422错误:
{"message":"ERROR :: /message/attributes/0/value/com.linkedin.common.MemberAttributedEntity :: unrecognized field found but not allowed\nERROR :: /message/attributes/0/value :: \"com.linkedin.common.MemberAttributedEntity\" is not a member type of union","status":422}
尝试微软官方文档提供的示例Schema时,又触发另一个422错误:
{"message":"ERROR :: /object :: field is required but not found and has no default value\n","status":422}
仅202306版本可正常运行,以下是该版本的完整可行请求示例:
POST https://api.linkedin.com/rest/socialActions/urn%3Ali%3Acomment%3A%28urn%3Ali%3Aactivity%3A7146485071443652608%2C7166522137988599809%29/comments HTTP/1.1 x-li-format: json LinkedIn-Version: 202306 X-Restli-Protocol-Version: 2.0.0 Authorization: Bearer ... Host: api.linkedin.com Content-Length: 465 { "actor": "urn:li:organization:101413098", "parentComment": "urn:li:comment:(urn:li:activity:7146485071443652608,7166522137988599809)", "message": { "text": "Santiago Acosta Ottonelli cierro por SL", "attributes": [ { "length": 25, "start": 0, "value": { "com.linkedin.common.MemberAttributedEntity": { "member": "urn:li:person:ARUhKQtm5a" } } } ] } }
解决方案
经过验证,202307及后续版本中,评论@提及需调整属性结构,使用com.linkedin.common.MentionEntity作为value类型,并指定object字段(被提及用户的URN),同时保持start和length与文本中用户名的位置匹配。调整后的完整请求示例如下:
POST https://api.linkedin.com/rest/socialActions/urn%3Ali%3Acomment%3A%28urn%3Ali%3Aactivity%3A7146485071443652608%2C7166522137988599809%29/comments HTTP/1.1 x-li-format: json LinkedIn-Version: 202307 X-Restli-Protocol-Version: 2.0.0 Authorization: Bearer ... Host: api.linkedin.com Content-Length: 465 { "actor": "urn:li:organization:101413098", "parentComment": "urn:li:comment:(urn:li:activity:7146485071443652608,7166522137988599809)", "message": { "text": "Santiago Acosta Ottonelli cierro por SL", "attributes": [ { "length": 25, "start": 0, "value": { "com.linkedin.common.MentionEntity": { "object": "urn:li:person:ARUhKQtm5a" } } } ] } }
关键调整点
- 将原
com.linkedin.common.MemberAttributedEntity替换为com.linkedin.common.MentionEntity - 把
member字段改为object字段,值保留被提及用户的URN
该格式可在202307及后续版本中正常通过校验,实现@提及功能。
内容的提问来源于stack exchange,提问作者malber
相关产品推荐
相关产品推荐

