Twitter API: Extracting Tweets with Specific Phrase

Twitter has been a good source for Data Mining. Many data scientists and analytics companies collect tweets and analyse them to understand people’s opinion about some matters.

In this tutorial, you will learn how to use Twitter API and Python Tweepy library to search for a word or phrase and extract tweets that include it and print the results.

First of all, you must install the Python Tweepy library. You can use this command in your Terminal.

Note that if you are on Mac or Linux, you might need to start with sudo  to avoid permissions issues.


Import the libraries you need.


Specify the phrase that you want to search.


Go to Twitter Developers page, and create a new app.

Enter your Consumer API keys, Access Token and Access Token Secret


This is the code you need for tweet listening from streaming API of Twitter.


Start tweet collection and filter tweets on basis of the given phrase.


Add the authentication for twitter’s streaming API and the main function.


Call the API with the phrase




Rating: 5.0/5. From 1 vote.
Please wait...

Leave a Reply