📜  Python – Tweepy 中的 API.statuses_lookup()

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

Python – Tweepy 中的 API.statuses_lookup()

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

API.statuses_lookup()

Tweepy 模块中API类的statuses_lookup()方法用于获取状态 ID 指定的状态,最大为 100。

示例 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)
  
# list of status IDs to be fetched 
id_ = [1266978261701210112, 1266735261012111360, 1266342841648898049]
  
# fetching the statuses
statuses = api.statuses_lookup(id_)
  
# printing the statuses
for status in statuses:
    print("The status " + str(status.id) + " is posted by " + status.user.screen_name)
    print("This status says : \n\n" + status.text, end = "\n\n")

输出 :

The status 1266978261701210112 is posted by geeksforgeeks
This status says : 

Avoid errors, not client calls
.
Geeks, Keep this going...
.
#sundayvibes #programming #programmingmemes #coding https://t.co/JkA5iStofZ

The status 1266735261012111360 is posted by geeksforgeeks
This status says : 

With the access to our Job Portal, find the jobs that are best for you & experience happy placement journey....
.
L… https://t.co/mzMMFVzjMv

The status 1266342841648898049 is posted by geeksforgeeks
This status says : 

My reaction to this Lockdown : 

"Der Lagi Lekin... Maine Ab Hai Jeena Seekh Liya" 

What's your reaction to it?
.… https://t.co/nH9L0eewSr

示例 2:使用带有 trim_user 参数的statuses_lookup()方法。

# list of status IDs to be fetched 
id_ = [1266978261701210112, 1266735261012111360, 1266342841648898049]
  
# fetching the statuses
statuses = api.statuses_lookup(id_, trim_user = True)
  
# printing the statuses
for status in statuses:
    print(status.user.id)

输出 :

57741058
57741058
57741058