Python – Tweepy 中的 API.retweets()
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。
转推()
Tweepy 模块中API
类的API.retweets()
方法用于返回推文的转发列表。
Syntax : API.retweets(parameters)
Parameters :
- id : The ID of the tweet which has to be retweeted.
- count : The number of retweets to be retrieved.
Returns : a list of objects of the class Status
示例 1:转发以下推文的用户列表:
# 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 tweet
ID = 1265889240300257280
# getting the retweeters
retweets_list = api.retweets(ID)
# printing the screen names of the retweeters
for retweet in retweets_list:
print(retweet.user.screen_name)
输出 :
harshitabambure
codedailybot
UVahalkar
codedailybot
ProjectLearn_io
codedailybot
ryokugyu_
AaronCuddeback
strong>示例 2:使用带有 count 参数的retweets()
方法仅获取一定数量的转推。仅打印以下推文的 3 个转发者的屏幕名称:
# the ID of the tweet
ID = 1263387365051183107
# number to retweets to be retrieved
count = 3
# getting the retweeters
retweets_list = api.retweets(ID, count)
# printing the screen names of the retweeters
for retweet in retweets_list:
print(retweet.user.screen_name)
输出 :
murali_ch
sushmitaraj13
rgsharma_me
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。