📜  Python – Tweepy 中的 API.retweets_of_me()

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

Python – Tweepy 中的 API.retweets_of_me()

Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。

API.retweets_of_me()

Tweepy 模块中API类的retweets_of_me()方法用于获取认证用户最近被他人转发的 20 条推文。

示例 1:使用不带任何参数的retweets_of_me()方法。

# 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)
  
# fetching the retweets
statuses = api.retweets_of_me()
  
print(str(len(statuses)) + " number of statuses have been retweeted.")

输出 :

20 number of statuses have been retweeted.

示例 2:使用带有 count 参数的retweets_of_me()方法仅获取指定数量的转推。

# screen name of the account to be fetched
screen_name = "geeksforgeeks"
  
# number of statuses to be fetched
count = 3
  
# fetching the retweets
statuses = api.retweets_of_me(count = count)
  
print(str(len(statuses)) + " number of statuses have been retweeted.")

输出 :

3 number of statuses have been retweeted.