Twitter Python API Tutorial

Playing around with the Twitter Python API.
Download:

wget http://code.google.com/p/python-twitter/downloads/detail?name=python-twitter-0.8.2.tar.gz

Extract:

tar -xvf python-twitter-0.8.2.tar.gz

Install Twitter (navigate inside the Twitter extracted folder)

sudo python setup.py install

Make sure Python Setuptool is installed

apt-get install python-setuptools

Install dependent files

httplib2-0.7.2$ sudo python setup.py install
simplejson-2.3.2$ sudo python setup.py install
simplegeo-python-oauth2-a83f4a2$ python setup.py build
simplegeo-python-oauth2-a83f4a2$ sudo python setup.py install

Register your Twitter application: https://dev.twitter.com/
Make sure you application Access Level is: Read, write, and direct messages.

Now we need to get access code for our application. Run get_access_token.py file with your consumer_key and consumer_secret inside that you got from creating your application.
Run:

sudo python get_access_token.py

It will show a link to to access with Passcode?. Click on the link to open and enter the Passcode value displayed in the webpage. It will then provide you with a access_token_key and access_token_secret which you can use in the code below:

List Twitter friends sample code:

import twitter
mytwitteraccount = twitter.Api(consumer_key='###', consumer_secret='###', access_token_key='###', access_token_secret='###')
friends=mytwitteraccount.GetFriends()
print[u.name for u in friends]

Make twitter post:

import twitter
mytwitteraccount = twitter.Api(consumer_key='###', consumer_secret='###', access_token_key='###', access_token_secret='###')
status=mytwitteraccount.PostUpdates('My first API call using Python')