Retrieve Latest Tweets – links up URLs, hashtags and @usernames

[javascript]
/*
Taken from http://www.sitepoint.com/blogs/2009/04/21/make-your-own-web-site-badges-with-jquery-and-json/
I’ve made some minor adjustments to make it easier to configure, and I’ve altered the output format too.

If you’re using this "as-is", make sure you have a <ul class="tweets"></ul> to drop your tweets into.
*/

twitter_user = ”;
twitter_count = 5;

twitter_url = "http://twitter.com/status/user_timeline/" + twitter_user + ".json?count=" + twitter_count + "&callback=?";

$.getJSON(twitter_url, function(data) {
$.each(data, function(i, item) {
var txt = item.text
.replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig, ‘<a href="$1">$1</a>’)
.replace(/@+([_A-Za-z0-9-]+)/ig, ‘<a href="http://twitter.com/#!/$1">@$1</a>’)
.replace(/#+([_A-Za-z0-9-]+)/ig, ‘<a href="http://search.twitter.com/#!/search/$1">#$1</a>’);

$(‘<li>’ + txt + ‘</li>’).appendTo(‘ul.tweets’);
});
});
[/javascript]

Leave a Reply