Open In App

Python – API.statuses_lookup() in Tweepy

Last Updated : 05 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 :




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


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.




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


Output :

57741058
57741058
57741058


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads