Skip to content

Instantly share code, notes, and snippets.

@pankajparashar-zz
Last active December 16, 2015 01:09
Show Gist options
  • Save pankajparashar-zz/5353033 to your computer and use it in GitHub Desktop.
Save pankajparashar-zz/5353033 to your computer and use it in GitHub Desktop.
Get the latest tweet from twitter.
var username = 'pankajparashar';
$.ajax({
url: 'https://api.twitter.com/1/statuses/user_timeline/' + username + '.json?count=1&include_rts=1&callback=?',
dataType: 'json',
error: function() { alert("Twitter is blocked"); },
success: function(data) {
var tweet = data[0].text;
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>';
});
$("#tweet").html(tweet);
$("#retweet").attr("href", tweet)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment