As part of the preDevCamp 2009 site, I created a JavaScript TwitterFeed today.

A sample can be seen here. If you leave this page open, it will constantly update with all Twitter tweets that contain the word ‘twitter’. It will update once every 5 seconds and will contain no more than the 25 most recent tweets.

Installing this code into a page of your own is very simple. You will need the following:

  • jQuery must be installed and you must include it in your webpage
  • tweetFeed.js must be included in your webpage
  • tweetFeed.css should be included, although the function will work without this file
  • A <div> with an id of ‘tweets’ somewhere on the page

With all of those in place, it’s a simple case of instantiating the feed:

var tf = new TweetFeed(searchString,feedPeriod,feedLength);

searchString
This is the string that is used to generate the feed. The feed will contain all tweets containing this word
feedPeriod
Number of seconds between each refresh of the feed
feedLength
Maximum number of tweets to show. At the moment, this must be > 15 or else the feed doesn't work properly.

All of the relevant code can be found by looking at the example, linked to above. Feel free to use this in any way you like. Comments are welcome