public
Last active

Basic tweet parsing via json and jquery

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<script>
$(document).ready(function(){
//Tell the function where the feed is located
$.getJSON("https://api.twitter.com/1/statuses/user_timeline.json?screen_name=tw2113&trim_user=1&count=5&include_rts=1&callback=?", function(data){
//Grab each of the "entries"
$.each(data, function(i,item){
//Create the links and throw them
//into the body of the page
function twitify( text ) {
// replace urls with linked ones
var t2 = text.replace(/(http|https)(:\/\/)([^ )]+)/ig, '<a href="$1$2$3">$1$2$3</a>' );
// replace @username with clickable twitter link
t2 = t2.replace(/@([^ ]+)/gi,'<a href="http://twitter.com/$1">@$1</a>');
// replace hashtags with Twitter searches
t2 = t2.replace(/#([^ ]+)/gi,'<a href="http://search.twitter.com/search?q=%23$1">#$1</a>');
return t2;
}
$("#tweets").append("<p>"+twitify(item.text)+"</p>");
});
});
});
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.