📜  Python Tweepy - 检查推文是否已被转发

📅  最后修改于: 2022-05-13 01:55:17.476000             🧑  作者: Mango

Python Tweepy - 检查推文是否已被转发

在本文中,我们将了解如何检查推文/状态是否已被经过身份验证的用户转发。 Status 对象的 retweeted 属性指示状态是否已被经过身份验证的用户转发。

在 GUI 中识别状态是否已由经过身份验证的用户转发:

在上述状态下,转推图标为绿色,因此经过身份验证的用户已转推推文。

示例 1:考虑以下状态:

我们将使用状态 ID 来获取状态。上述状态的状态 ID 为 1272771459249844224。

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# the ID of the status
id = 1272771459249844224
  
# fetching the status
status = api.get_status(id)
  
# fetching the retweeted attribute
retweeted = status.retweeted 
  
if retweeted == True:
    print("The authenticated user has retweeted the tweet.")
else:
    print("The authenticated user has not retweeted the tweet.")

输出 :

The authenticated user has not retweeted the tweet.

示例 2:考虑以下状态:

我们将使用状态 ID 来获取状态。上述状态的状态 ID 为 1272479136133627905。

# the ID of the status
id = 1272479136133627905
  
# fetching the status
status = api.get_status(id)
  
# fetching the retweeted attribute
retweeted = status.retweeted 
  
if retweeted == True:
    print("The authenticated user has retweeted the tweet.")
else:
    print("The authenticated user has not retweeted the tweet.")

输出 :

The authenticated user has retweeted the tweet.