Pages Navigation Menu

Software Mastery, the Fun Way

Twitter API: Accessing timeline data

In Chapter 7 of Head First HTML5 Programming, we create a JSONP web application called Tweetshirt. We use Twitter JSON data to create a tweet menu, so you can choose a tweet to add to a <canvas> element.

Unfortunately, Twitter is in the process of deprecating the API that allows us to access a user’s timeline of tweets, and replacing it with an API that requires the user of the application accessing the timeline to authenticate first. This means the URL to access the JSON data of a Twitter user’s timeline on page 322 no longer works.

Twitter has temporarily moved the API URL to:

http://api.twitter.com/1/statuses/user_timeline/wickedsmartly.json?callback=updateTweets (Update: this URL may stop working at any time!)

but this URL may go away in the next few months, as they replace the old API with the new one that requires authentication.

In case that happens, we have created a JSONP service that creates “fake tweets”. It behaves just like the Twitter API, and returns an array of tweets, as a call to the callback you provide to the URL:

http://tweetshirt.wickedlysmart.com/?callback=updateTweets

So if you’re implementing Tweetshirt as you read Head First HTML5 Programming, you can replace the URL on page 322 with the URL above and continue with the example as written in the book.

Web applications that need to access JSON data that requires authentication, such as data on Twitter or Facebook, can authenticate using a standard called OAuth. We’ll post about OAuth on the WickedlySmart blog in the future, but OAuth is beyond the scope of the book. By creating our own fake tweeting service, we can keep the example simple and keep the chapter focused on the <canvas> element.

Thanks to chethStudios.net for the Tweetshirt icon.

Update: Twitter has completed the deprecation process for API version 1, so the temporary Twitter URL above will no longer work any day now. You can use our “fake tweet” service, or implement your own server-side code to retrieve Tweets using OAuth. If you want to do that, take a look at this article: http://wickedlysmart.com/twitternews-oauth/.