📌  相关文章
📜  Python – Tweepy 中的 API.mentions_timeline()

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

Python – Tweepy 中的 API.mentions_timeline()

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

API.mentions_timeline()

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

示例 1:使用没有任何参数的mentions_timeline()方法。

# 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.mentions_timeline()
  
print(str(len(statuses)) + " number of statuses have been mentioned.")

输出 :

20 number of statuses have been mentioned.

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

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

输出 :

3 number of statuses have been mentioned.