Python – API.statuses_lookup() in Tweepy

Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.

API.statuses_lookup()

The statuses_lookup() method of the API class in Tweepy module is used to get the statuses specified by the status IDs, up to 100.

Syntax : API.statuses_lookup(parameters)

Parameters :

  • id_ : A list of Tweet IDs to fetch, up to 100
  • trim_user : A boolean indicating if user IDs should be provided, instead of complete user objects, the default value is False.

Returns : a list of objects of the class Status



Example 1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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")

chevron_right


Output :

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

Example 2: Using the statuses_lookup() method with the trim_user parameter.

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

57741058
57741058
57741058



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.