The twitter python binding can be found in
http://code.google.com/p/python-twitter/
Before you install it, you need to install simplejson.
http://cheeseshop.python.org/pypi/simplejson
To install simplejson, it is just get the tar.gz file. Then uncompress it,
Then in the same directory
On ubuntu:
sudo python setup.py installon other linux as root:
python setup.py installsame on windows. just:
python setup.py install
The process of installing the python-twitter is the same cycle of python setup.py
There is a few standard thing we can do with the python-twitter module.
here I assume that, you run it, in a python shell, it is just a follow along tutorial here, and the >>> is not shown:
before that, import the module
import twitterstart using it, you need to authenticate yourself, using your twitter username and password.
api=twitter.Api("username","password")to view public time line
status=api.GetPublicTimeline()or you can just
for s in status:
print s.text
status=api.GetPublicTimeline()to view a user status, just replace user with the username of the user
print [s.text for s in status]
userStatus=api.GetUserTimeline("user")then read it by
print [t.text for t in userStatus]Here is the important one, to post your own status using the python-twitter module
posting=apt.PostUpdate("your status")There you go, few way to use python to interface with twitter. You can use this with a gui front end, or integrate with django, etc.
No comments:
Post a Comment