Last active
December 16, 2015 01:09
-
-
Save pankajparashar-zz/5353033 to your computer and use it in GitHub Desktop.
Get the latest tweet from twitter.
This file contains 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
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