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

Tweepy为何将带引用的转发识别为引用推文?如何正确检测?

解决Tweepy中识别转发状态与获取完整文本的问题

针对你遇到的两个问题,我来一步步帮你梳理解决:


问题1:正确检测推文是否为转发(包含带引用的转发)

你这里混淆了status.retweeted属性的真实含义——它表示的是当前授权的用户是否转发过这条推文,而不是这条推文本身是不是一条转发内容。这就是为什么你看到结果是false,但实际这是一条带引用的转发(Quote Retweet)。

要覆盖所有转发场景,需要区分两种情况:

  • 普通无评论转发:这类推文会携带retweeted_status字段,可通过检查是否存在该字段来判断。
  • 带引用的转发(Quote Retweet):这类推文会标记is_quote_status=True,同时包含quoted_status_id字段(默认API请求会包含,显式声明更稳妥)。

修改后的判断逻辑可以覆盖所有转发类型:

# 检测普通无评论转发
if hasattr(status, 'retweeted_status'):
    print('普通转发:', status.retweeted_status.full_text)
# 检测带引用的转发
elif status.is_quote_status and hasattr(status, 'quoted_status_id'):
    qstatus = tweepy_api.get_status(status.quoted_status_id, tweet_mode='extended')
    print('转发评论内容:', status.full_text)
    print('被引用推文:', qstatus.full_text)
# 普通原创推文
else:
    print('原创推文:', status.full_text)

问题2:获取带引用转发的完整文本

你已经使用了tweet_mode='extended',这是正确的操作,但需要注意两个细节:

  1. 带引用转发的status.full_text本身就是当前推文(含你的评论+引用链接)的完整内容,不会被截断;
  2. 获取被引用的推文时,必须确保同样传入tweet_mode='extended'——你的代码里已经做到了这一点,这部分是正确的。

如果还是觉得文本不完整,可能是因为你把被引用推文的内容和当前转发的评论内容混淆了:当前转发的评论内容在status.full_text里,被引用的推文内容需要通过单独获取的qstatus.full_text查看。

给你整理了修正后的完整测试代码:

import tweepy
from tweepy import OAuthHandler

consumer_key = '...'
consumer_secret = '...'
access_token = '...'
access_secret = '...'

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

tweepy_api = tweepy.API(auth)

status_id = 999280226994671616
# 显式声明include_entities,确保能获取到quoted_status_id
status = tweepy_api.get_status(status_id, tweet_mode='extended', include_entities=True)

print(f"推文发布者: @{status.user.screen_name}")

# 修正后的转发检测逻辑
if hasattr(status, 'retweeted_status'):
    print(f"\n【普通转发】\n原推文内容: {status.retweeted_status.full_text}")
elif status.is_quote_status:
    try:
        qstatus = tweepy_api.get_status(status.quoted_status_id, tweet_mode='extended')
        print(f"\n【带引用的转发】\n评论内容: {status.full_text}")
        print(f"被引用推文内容: {qstatus.full_text}")
    except tweepy.TweepError as e:
        print(f"\n获取被引用推文失败: {e}")
else:
    print(f"\n【原创推文】\n内容: {status.full_text}")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 10:03:50