Skip to content
Related Articles

Related Articles

Python – Status object in Tweepy
  • Last Updated : 03 Jul, 2020

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.

Status

The Status object in Tweepy module contains the information about a status/tweet.

Here are the list of attributes in the Status object :

  • created_at : The time the status was posted.
  • id : The ID of the status.
  • id_str : The ID of the status as a string.
  • text : The text of the status.
  • entities : The parsed entities of the status such as hashtags, URLs etc.
  • source : The source of the status.
  • source_url : The URL of the source of the status.
  • in_reply_to_status_id : The ID of the status being replied to.
  • in_reply_to_status_id_str : The ID of the status being replied to in as a string.
  • in_reply_to_user_id : The ID of the user being replied to.
  • in_reply_to_user_id_str : The ID of the user being replied to as a string.
  • in_reply_to_screen_name : The screen name of the user being replied to
  • user : The User object of the poster of the status.
  • geo : The geo object of the status.
  • coordinates : The coordinates of the status.
  • place : The place of the status.
  • contributors : The contributors of the status.
  • is_quote_status : Indicates whether the status is a quoted status or not.
  • retweet_count : The number of retweets of the status.
  • favorite_count : The number of likes of the status.
  • favorited : Indicates whether the status has been favourited by the authenticated user or not.
  • retweeted : Indicates whether the status has been retweeted by the authenticated user or not.
  • possibly_sensitive : Indicates whether the status is sensitive or not.
  • lang : The language of the status.

Example : Consider the following status :

Use get_status() method to fetch the status.




# 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 = 1268080321590935553
  
# fetching the status
status = api.get_status(id)
  
# printing the information
print("The status was created at : " + str(status.created_at))
print("The id is : " + str(status.id))
print("The id_str is : " + status.id_str)
print("The text is : " + status.text)
print("The entitities are : " + str(status.entities))
print("The source is : " + status.source)
print("The source_url is : " + status.source_url)
  
  
print("The in_reply_to_status_id is : " + str(status.in_reply_to_status_id))
print("The in_reply_to_status_id_str is : " + str(status.in_reply_to_status_id_str))
print("The in_reply_to_user_id is : " + str(status.in_reply_to_user_id))
print("The in_reply_to_user_id_str is : " + str(status.in_reply_to_user_id_str))
print("The in_reply_to_screen_name is : " + str(status.in_reply_to_screen_name))
  
  
print("The poster's screen name is : " + status.user.screen_name)
print("The geo is : " + str(status.geo))
print("The coordinates are : " + str(status.coordinates))
print("The place is : " + str(status.place))
print("The contributors are : " + str(status.contributors))
print("The is_quote_status is : " + str(status.is_quote_status))
print("The retweet_count is : " + str(status.retweet_count))
print("The favorite_count is : " + str(status.favorite_count))
  
print("Has the authenticated user favourited the status? : " + str(status.favorited))
print("Has the authenticated user retweeted the status? " + str(status.retweeted))
print("Is the status possibly_sensitive? : " + str(status.possibly_sensitive))
print("The lang is : " + status.lang)

Output :



The status was created at : 2020-06-03 07:21:23
The id is : 1268080321590935553
The id_str is : 1268080321590935553
The text is : Time really hits differently when you are
??holding a plank for a minute,
??washing your hands for 20 seconds, and… https://t.co/BBg2RIamGy
The entitities are : {‘hashtags’: [], ‘symbols’: [], ‘user_mentions’: [], ‘urls’: [{‘url’: ‘https://t.co/BBg2RIamGy’, ‘expanded_url’: ‘https://twitter.com/i/web/status/1268080321590935553’, ‘display_url’: ‘twitter.com/i/web/status/1…’, ‘indices’: [116, 139]}]}
The source is : Twitter Web App
The source_url is : https://mobile.twitter.com
The in_reply_to_status_id is : None
The in_reply_to_status_id_str is : None
The in_reply_to_user_id is : None
The in_reply_to_user_id_str is : None
The in_reply_to_screen_name is : None
The poster’s screen name is : geeksforgeeks
The geo is : None
The coordinates are : None
The place is : None
The contributors are : None
The is_quote_status is : False
The retweet_count is : 2
The favorite_count is : 31
Has the authenticated user favourited the status? : True
Has the authenticated user retweeted the status? False
Is the status possibly_sensitive? : False
The lang is : en

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :