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')
Thanks you
Thys
This blog is help me for my first task..
I was doing first time this such kind of for integrating twitter with python by this blog i done it very easily….
Hi Anil, glad my blog was an help to you!:)
This was very helpful Thys… Thank you… I was having a heck of a time importing the necessary modules…. I am trying to search Twitter for my thesis project… Could you possible show how to export tweets to MySQLdb? If not, thank you anyway for this…
Hi there, I am completely new to Python (and programming). I put this (wget http://code.google.com/p/python-twitter/downloads/detail?name=python-twitter-0.8.2.tar.gz) into my command line.
This is what was returned.
-bash: wget: command not found
Any thoughts?