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

使用Tweepy通过conversation_id获取Twitter推文线程的问题与解决

利用Twitter API v2.0的conversation_id获取完整推文线程

Twitter API v2.0新增了conversation_id字段,用来更便捷地获取完整的推文线程。之前追踪回复只能依赖原推文的in_reply_to_status_id字段,这种方式处理原推文的一级回复还算简单,但要处理回复的回复时就非常繁琐。

我曾尝试用Tweepy通过conversation_id搜索推文,代码如下:

replies=[]
for tweet in tweepy.Cursor(api.search_tweets,q='conversation_id:<1565355188004741120>',timeout=999999).items(1000):
        replies.append(tweet)

但返回的replies列表是空的,而这个conversation_id是有效的(已通过旧代码获取到一级回复)。经排查,问题出在API版本差异上,改用Twitter API v2.0对应的Tweepy代码即可解决:

replies=[]
for tweet in tweepy.Paginator(client.search_recent_tweets, query='conversation_id:1565355188004741120'):
        replies.append(tweet)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 07:44:16