【问题标题】:Why does twitter API add url at the end of the text为什么twitter API在文本末尾添加url
【发布时间】:2023-03-27 16:31:01
【问题描述】:

使用 twitter API 获取推文信息时,返回的 textfull_text 字段会在文本末尾附加一个 URL。例如:

    "full_text": "Just another Extended Tweet with more than 140 characters, generated as a documentation example, showing that [\"truncated\": true] and the presence of an \"extended_tweet\" object with complete text and \"entities\" #documentation #parsingJSON #GeoTagged https://twitter.com/FloodSocial/status/994633657141813248"

https://twitter.com/FloodSocial/status/994633657141813248 附加在末尾(附加的 url 实际上是一个缩短的 url,但 stackoverflow 不允许在正文中使用缩短的 url,所以我只是用完整的 URL 替换它)。为什么 API 会添加这个,有没有办法在没有添加 URL 的情况下获取文本?

【问题讨论】:

    标签: ruby twitter rubygems


    【解决方案1】:

    您使用的是正确的 Twitter gem 吗?使用gem install twitter 并设置客户端according to the docs,您应该能够通过其ID 获取推文/状态。但是,无论您使用什么示例,都无法显示您是如何获得全文的

    text = client.status('994633657141813248').text
    =>"Just another Extended Tweet with more than 140 characters, generated as a documentation example, showing that https://twitter.com/FloodSocial/status/994633657141813248"
    

    url 被截断为纯字符串,所以不确定你甚至做了什么来得到你制定的字符串。

    但是如果你有一些嵌入了 url 的长字符串,你可以这样做

    text.split(/\shttp?s/).first
    

    【讨论】:

    【解决方案2】:

    这看起来像是包含原始推文 URL 的引用推文?

    [编辑 - 我对上述说法有误]

    我明白发生了什么。原始推文链接到 Twitter 上的图像(https://twitter.com/FloodSocial/status/994633657141813248/photo/1,通过缩短的 tco 链接)。 Twitter 在呈现的推文中隐藏图像 URL,但在文本正文中返回它。这是这种情况下的预期行为。您还可以在推文数据的extended_entities 段中看到解析出的链接,以及推文同一区域中的图像数据本身。如果您想从文本数据中省略 URL,则需要自己修剪。

    【讨论】:

    • 原推文中没有网址。该 URL 被添加到 twitter gem 返回的负载中。
    猜你喜欢
    • 2014-02-03
    • 2020-10-31
    • 1970-01-01
    • 2017-06-15
    • 2021-10-21
    • 2012-12-19
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多