Created
October 20, 2011 23:16
-
-
Save fideloper/1302690 to your computer and use it in GitHub Desktop.
Get public Twitter timeline with jQuery ajax - with retweets
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
$.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