Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created October 20, 2011 23:16
Show Gist options
  • Save fideloper/1302690 to your computer and use it in GitHub Desktop.
Save fideloper/1302690 to your computer and use it in GitHub Desktop.
Get public Twitter timeline with jQuery ajax - with retweets
$.ajax({
type:'GET',
dataType:'jsonp',
url:'http://api.twitter.com/1/statuses/user_timeline.json',
data:{screen_name:'USERNAME', include_rts:1}, //show retweets
success:function(data, textStatus, XMLHttpRequest) {
var tmp = false;
var results = $('#twitter_results');
//console.log(data);
for(i in data) {
if(data[i].retweeted_status != null) {
tmp = $('<li class="retweet" itemid="'+data[i].retweeted_status.id_str+'"><div class="dogear"></div><img src="'+data[i].retweeted_status.user.profile_image_url+'" alt="" align="left" width="48" height="48" /><cite>'+data[i].retweeted_status.user.screen_name+'</cite><p>'+data[i].retweeted_status.text.linkify_tweet()+'</p></li>');
if(data[i].retweeted_status.favorited) {
tmp.addClass('favorite');
}
} else {
tmp = $('<li itemid="'+data[i].id_str+'"><div class="dogear"></div><img src="'+data[i].user.profile_image_url+'" alt="" align="left" width="48" height="48" /><cite>'+data[i].user.screen_name+'</cite><p>'+data[i].text.linkify_tweet()+'</p></li>');
if(data[i].favorited) {
tmp.addClass('favorite');
}
}
results.append(tmp);
}
},
error:function(req, status, error) {
alert('error: '+status);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment