Sunday, January 23, 2011

python-twitter-tools wins!

(1) install python-twitter-tools
(2) Register an app with twitter to get oath credentials
(3) Run this code ftw!
(4) You'll need to set those four variables to the ones you got in step 2 for this to work of course

python-twitter-tools has the most natural twitter API I've seen. It's really beautiful. The namespace follows the restful API urls, so you don't need any documentation other than what's on the twitter dev website. It really does Just Work.

import twitter

if __name__ == "__main__":

    oa = twitter.oauth.OAuth(access_key, access_secret, consumer_key, consumer_secret)
    tw = twitter.Twitter(auth=oa)
    followers = tw.statuses.followers()
    print "You have", len(followers), "followers"
    for f in followers:
        print f['name']