Related Articles

Related Articles

Python Tweepy – Getting the text of a tweet
  • Last Updated : 18 Jun, 2020

In this article we will see how we can get the text of a status/tweet. A tweet can only have a maximum of 280 characters. The text attribute of the Status object provides us with the text of the status.

Identifying the text of the status in the GUI :

In the above mentioned status, the text of the status is :

A programmer’s takeaway from the pandemic: Local variables over Global variables.

 What do you think?
.
.
.
.
.
#programming #coding  #programmingmemes #Covid_19 #codinglife #Python #javascript 
#pandemic #thursdayvibes

In order to get the text of the status, 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. If we want to get the complete text, pass another parameter tweet_mode = "extended".
  3. From this object, fetch the text attribute present in it. If we want to get the complete text, fetch the attribute full_text.

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.

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)
  
# the ID of the status
id = 1272771459249844224
  
# fetching the status
status = api.get_status(id)
  
# fetching the text attribute
text = status.text 
  
print("The text of the status is : \n\n" + text)

chevron_right


Output :

The text of the status is : 

Which movie did you watch recently?

Reply us!
.
.
.
.
.
#tuesdaymood #TuesdayThoughts #Bollywood #Hollywood #genre 
#movies #movie #fun

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. This time we will be fetching the complete text of the status. While using the get_status() method also pass tweet_mode = "extended" as a parameter. Then fetch the complete text using the full_text attribute.

filter_none

edit
close

play_arrow

link
brightness_4
code

# the ID of the status
id = 1272479136133627905
  
# fetching the status with extended tweet_mode
status = api.get_status(id, tweet_mode = "extended")
  
# fetching the full_text attribute
full_text = status.full_text 
  
print("The text of the status is : \n\n" + full_text)

chevron_right


Output :

The text of the status is : 

"I am thankful to programming for _______________."

Reply us most quirky/unexpected answers!
.
.
.
.
.
.
.
#coding #programming #codinglife #code #javascript #NodeJS  #reactjs #100DaysOfCode #codingisfun

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 :