Thursday 6 June 2013

Twitter API Changes

Twitter are gently rolling out a number of changes as they move from API v1.0 to v1.1.  I use the Twitter API in my social media display application 'Chrysanthemum'.  This blog gives an overview of Twitter's changes in moving to Twitter API v1.1 and considers how it will affect my Chrysanthemum application (Moderated Twitter Feed for Live Events).
Twitter helpfully told us about the changes on their website: Overview: Version 1.1 of the Twitter API.  The key ones that affect my Twitter To Big Screen Mac OSX application are:
  • Authentication required on all 'endpoints'
  • Display guidelines become requirements
  • Dropping XML, Atom and RSS results in favour of JSON
  • Improved rate limits (number of request~responses)

API v1 Retirement: Final Dates announced that API v1.0 will be closed on 11th June 2013 preceded by a number of blackout tests announced on the Twitter developer's blog.  During blackouts requests to search.twitter.com/search.* will receive HTTP 410 Gone which would break Chrysanthemum.


Updates required

Do application only authentication.

Twitter API v1.1 requires applications to authenticate all of their requests using either OAuth 1.0a or Application-only authentication.  Chrysanthemum does not need to do anything that a user would need to be logged in to do e.g. sending, replying or retweeting tweets.  It only needs to fetch publicly available tweets and select some of those for display in an aesthetically pleasing branded manner.  This only requires Application-Only Authentication.  This is good because it's a lot simpler than OAuth.

Use GET search/tweets instead of search.twitter.com/search.*

While looking into the changes and preparing for an update I revisited the method of fetching tweets.  I read about twitter's Streaming API as opposed to REST API - the Streaming API documentation includes a comparison of the two.

Streaming API constantly receives tweets as they come in.
REST API needs a request to fetch tweets.

Chrysanthemum is written to fetch tweets from search.twitter.com on a button press so REST API would be most compatible with the existing software.  Streaming tweets are available from Twitter data reselling partners offering more search capabilities such as sentiment, influence and demographics which might be a nice offering to show organisers, but at a cost I assume..

On reflection I don't think the use cases of Chrysanthemum *need* the streaming API which could take resources away from the all important display code.  If I implement Chrysanthemum using something like cloudbase.io to share data across computers then Streaming API may become more feasible.  For now giving the moderator control over when tweets are downloaded is the default position and I may add the option to manually request tweet fetching or turn on the hosepipe.

My initial solution was to go for App-only REST requests as described in my Twitter OAuth Cocoa post.

Use JSON instead of XML

I don't care why JSON is better than XML, I only care that Twitter think it is the way to go due to overwhelming popularity and smaller filesizes.  From a programming point of view it's not that different, in fact it might be easier to parse JSON than XML.  The awesome stackoverflow is a good place to start understanding how to Parse JSON in Objective C.  The JSON outputs from twitter API calls *may* contain some or all or a lot of tweet fields including entities such as media, urls and hashtags.  These fields are the things I need to extract from the twitter stream for Chrysanthemum.

Use SSL and verify peers as non-SSL requests will eventually be rejected. 

This may not be required as I'm not using user data.  Application-only authentication allows access only to public information so the added security of SSL is not required.  However, if non-SSL requests end up being rejected for App-only Auth then this may have to be implemented.  For now this is on the possible list of updates

No comments:

Post a Comment