Posted By

nikefido on 12/02/10


Tagged

jquerytwitterpublic timelinetwitter timelineajax


Versions (?)

Who likes this?

9 people have marked this snippet as a favorite

verostudios
luman
kwameboame
nickian
virendrakryadav
czehner
jondiscipulo
ringo380
VeXHarbinger


Get public Twitter timeline with jQuery ajax - with retweets


 / Published in: jQuery
 

This is a snippet for grabbing and displaying a public user twitter timeline from Twitter's API using jQuery ajax(). As a bonus, it also gives some hinting on how to test if its a retweet, and if so, grab the original tweeter's information - so the timeline looks more like twitter.com's timline.

  1. $.ajax({
  2. type:'GET',
  3. dataType:'jsonp',
  4. url:'http://api.twitter.com/1/statuses/user_timeline.json',
  5. data:{screen_name:'USERNAME', include_rts:1}, //show retweets
  6. success:function(data, textStatus, XMLHttpRequest) {
  7. var tmp = false;
  8. var results = $('#twitter_results');
  9. console.log(data);
  10. for(i in data) {
  11. if(data[i].retweeted_status != null) {
  12. 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>');
  13. if(data[i].retweeted_status.favorited) {
  14. tmp.addClass('favorite');
  15. }
  16. } else {
  17. 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>');
  18. if(data[i].favorited) {
  19. tmp.addClass('favorite');
  20. }
  21. }
  22.  
  23. results.append(tmp);
  24. }
  25. },
  26. error:function(req, status, error) {
  27. alert('error: '+status);
  28. }
  29. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: nikefido on December 2, 2010

You may want to remove "console.log(data)" as well.

You need to login to post a comment.