Friday, December 27, 2024
Google search engine
HomeLanguagesPython Tweepy – Checking whether a tweet has been retweeted or not

Python Tweepy – Checking whether a tweet has been retweeted or not

In this article we will see how we can check whether a tweet/status has been retweeted by the authenticated user or not. The retweeted attribute of the Status object indicates whether the status has been retweeted by the authenticated user or not.

Identifying whether the status has been retweeted by the authenticated user or not in the GUI :

In the above mentioned status, the retweet icon is in green color, therefore the authenticated user has retweeted the tweet.

In order to check whether the status has been retweeted by the authenticated user or not, we have to do the following :

  1. Identify the status ID of the status from the GUI.
  2. Get the Status object of the status using the get_status() method with the status ID.
  3. From this object, fetch the retweeted attribute present in it.

Example 1 : Consider the following status :

We will use the status ID to fetch the status. The status ID of the above mentioned status is 1272771459249844224.




# 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 status
id = 1272771459249844224
  
# fetching the status
status = api.get_status(id)
  
# fetching the retweeted attribute
retweeted = status.retweeted 
  
if retweeted == True:
    print("The authenticated user has retweeted the tweet.")
else:
    print("The authenticated user has not retweeted the tweet.")


Output :

The authenticated user has not retweeted the tweet.

Example 2 : Consider the following status :

We will use the status ID to fetch the status. The status ID of the above mentioned status is 1272479136133627905.




# the ID of the status
id = 1272479136133627905
  
# fetching the status
status = api.get_status(id)
  
# fetching the retweeted attribute
retweeted = status.retweeted 
  
if retweeted == True:
    print("The authenticated user has retweeted the tweet.")
else:
    print("The authenticated user has not retweeted the tweet.")


Output :

The authenticated user has retweeted the tweet.

Last Updated :
18 Jun, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments