Created
March 27, 2012 15:34
-
-
Save nikhgupta/2217068 to your computer and use it in GitHub Desktop.
jQuery: get latest tweet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// set your twitter id | |
var user = 'quenesswebblog'; | |
// using jquery built in get json method with twitter api, return only one result | |
$.getJSON('http://twitter.com/statuses/user_timeline.json?screen_name=' + user + '&count=1&callback=?', function(data) { | |
// result returned | |
var tweet = data[0].text; | |
// process links and reply | |
tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) { | |
return '<a href="'+url+'">'+url+'</a>'; | |
}).replace(/B@([_a-z0-9]+)/ig, function(reply) { | |
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>'; | |
}); | |
// output the result | |
$("#tweet").html(tweet); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v1.0 of the Twitter API is no longer active, so this code does not work :(