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

如何通过LinkedIn API请求过滤仅获取纯文本评论内容?

LinkedIn API 获取纯文本内容的解决办法
  • 结论:LinkedIn Posts API目前不支持通过请求参数直接过滤仅返回纯文本,没法在请求里加参数去掉提及、话题标签这类元素,必须拿到完整响应后自行处理提取。

  • 处理步骤:

    • 解析API返回结果中content字段下的elements数组(这是LinkedIn存储帖子内容的标准结构)
    • 遍历数组,只提取type为TextElement的text内容,忽略MentionElement、HashtagTemplate类型的元素

代码示例(Python)

针对你提供的示例内容,处理逻辑如下:

def extract_plain_text(content_elements):
    plain_text = ""
    for elem in content_elements:
        if elem["type"] == "TextElement":
            plain_text += elem["text"]
    return plain_text

# 模拟API返回的内容元素结构
sample_elements = [
    {"type": "TextElement", "text": "恭喜 "},
    {"type": "MentionElement", "mention": {"urn": "urn:li:person:6sc1MHJfcE"}, "text": "@[Becca Meinz]"},
    {"type": "TextElement", "text": "——百思买端到端供应链战略副总裁,入选"},
    {"type": "MentionElement", "mention": {"urn": "urn:li:organization:683279"}, "text": "@[Business Insider]"},
    {"type": "TextElement", "text": "的“百位商业变革人物”榜单。 https://bby.me/wj29an"}
]

# 提取纯文本
result = extract_plain_text(sample_elements)
print(result)
# 输出:恭喜 ——百思买端到端供应链战略副总裁,入选的“百位商业变革人物”榜单。 https://bby.me/wj29an

补充说明

如果想保留提及对象的名称(比如把@[Becca Meinz]替换成“Becca Meinz”),可以从MentionElement的mention字段获取对应URN,再调用LinkedIn的用户/组织信息接口获取名称后替换,不过这需要额外的API请求权限。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 03:25:29