Introduction: 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.
Steps to obtain keys:
– Login to twitter developer section
– Go to “Create an App”
– Fill the details of the application.
– Click on Create your Twitter Application
– Details of your new app will be shown along with consumer key and consumer secret.
– For access token, click ” Create my access token”. The page will refresh and generate access token.
Tweepy is one of the library that should be installed using pip. Now in order to authorize our app to access Twitter on our behalf, we need to use the OAuth Interface. Tweepy provides the convenient Cursor interface to iterate through different types of objects. Twitter allows a maximum of 3200 tweets for extraction.
These all are the prerequisite that have to be used before getting tweets of a user.
Code(with explanation) :
The above script would generate all the tweets of the particular user and would be appended to the empty array tmp. Here Tweepy is introduced as a tool to access Twitter data in a fairly easy way with Python. There are different types of data we can collect, with the obvious focus on the “tweet” object. Once we have collected some data, the possibilities in terms of analytics applications are endless.
One such application of extracting tweets is sentiment or emotion analysis. The emotion of the user can be obtained from the tweets by tokenizing each word and applying machine learning algorithms on that data. Such emotion or sentiment detection is used worldwide and will be broadly used in the future.
This article is contributed by Ayush Govil. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python Tweepy – Getting the number of tweets a user has liked
- Python Tweepy – Getting the number of tweets a user has tweeted
- Extract Tweets using GetOldTweets3
- Python | Foreground Extraction in an Image using Grabcut Algorithm
- Python | Words extraction from set of characters using dictionary
- Text Detection and Extraction using OpenCV and OCR
- Python - Edge extraction using pgmagick library
- Feature Extraction Techniques - NLP
- Python | Prefix extraction before specific character
- NLP | Proper Noun Extraction
- NLP | Location Tags Extraction
- Sklearn | Feature Extraction with TF-IDF
- Python - Rear element extraction from list of tuples records
- Python | Prefix extraction depending on size
- Python - Phrase extraction in String
- Python - Ordered tuples extraction
- Python - API.create_friendship() in Tweepy
- Python - API.get_user() in Tweepy
- Python - API.me() in Tweepy
- Python - API.lookup_users() in Tweepy