Twitter API 1.0 goes 410 Gone, time to upgrade to 1.1

June 15, 2013 - Alex - twitter - python - Software

After quite a few warnings Twitter finally pulled the plug on API 1.0 last Tuesday, leading to quite a few Twitter applications to break. Their new API has been around for some time, but as OAuth authentication for all endpoints to the new API is required (combined with stringent rate-limiting and no longer being able to get RSS, Atom or XML responses) transitioning to it understandably wasn't a top priority.

That has now changed, as any request against the 1.0 API is now greeted with a 410 Gone response. Dev Twitter has been ablaze with discussions about the forced upgrade but there is little we can do about it: time to upgrade!

With 1.0 requests against the API were very easy so you could get away with doing your requests with urllib2 or requests. With 1.1 and forced OAuth authentication this no longer is the way to go, thankfully there are a quite a few Python Twitter libraries. Python-twitter is probably the best choice. Stay clear from older libraries that haven't been updated this year: API 1.1 came out in September 2012 so any library from before that time won't work anymore.

The next step is getting your OAuth consumer and access keys. If you don't have a Twitter account it's time to sign up, after that head on to dev.twitter.com/apps and register your application. Make sure to read all the requirements as Twitter has limited the terms considerably.

You now have your consumer key and consumer secret settings. Generate your access token to get your access token key and access token secret: you need all 4 to authenticate with the 1.1 API. A quick example for searching & posting with python-twitter:

>>> import twitter
>>> api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret',
                      access_token_key='access_token', access_token_secret='access_token_secret')

>>> api.PostUpdate('Python-twitter rocks! #python')
>>> for status in api.GetSearch('#python'):
        print status.text

Thanks to python-twitter interacting with API 1.1 is easy. It is a pity that Twitter has done away with their open-access API but c'est la vie...



Latest Tweets