Rohit Agarwal's Notes

Search twitter from command-line

06 Jun 2013

Recently, I started learning the Twitter API. Twitter has deprecated v1 of its API, and the v1.1 of its API requires the use of OAuth.

So, the first step is to download an OAuth library. I am going to use simplegeo/python-oauth2. You can download it from pypi and install it by executing sudo ./setup.py install.

Here is a script which uses the API to search twitter from the terminal.

To use this script, you first need to create an application at https://dev.twitter.com/apps

You will get your consumer_key and consumer_secret from there. You will also need to create an access token for your account. After doing that you will get your access_token_key and access_token_secret.

Fill these four values in twitter_search.py and you are good to go.

$ python twitter_search.py SEARCH TERM(S)