Posted By

bchhun on 11/17/11


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mmcachran
VeXHarbinger


Grab Tweets


 / Published in: JavaScript
 

  1. function getTweets(handle, tweetHash) {
  2.  
  3. // Create a ul for the Twitter statuses:
  4. var twitter_nod = jQuery('<ul id="twitter-feed"></ul>').insertAfter("#tweets");
  5. var maxTweets = 3;
  6. // Get & parse json object:
  7. var JSONCallback = function(data) {
  8. var html = '';
  9. var count = 0;
  10.  
  11.  
  12. $.each(data, function(i,item) {
  13.  
  14. var content_str = item.text;
  15. var content_created = item.created_at;
  16.  
  17. if (item.text.toLowerCase().indexOf(tweetHash) === -1 || count > maxTweets) {
  18. return true; /*continue*/
  19. }
  20.  
  21. content_str = content_str.replace(/http:\/\/\S+/g, '<a href="$&" class="external" rel="nofollow">$&</a>');
  22. content_str = content_str.replace(/(@)(\w+)/g, ' @<a href="http://twitter.com/$2" class="external" rel="nofollow">$2</a>');
  23. content_str = content_str.replace(/(#)(\w+)/g, ' #<a href="http://search.twitter.com/search?q=%23$2" class="external" rel="nofollow">$2</a>');
  24. //evenOdd_str = i % 2 == 0 ? 'odd' : 'even';
  25. //$("#twitter-feed").append('<li class="'+evenOdd_str+'">'+content_str +'</li>');
  26.  
  27. html += '<p>' + content_str + '<span id="tweet-date">' + calcTime(content_created) + '</span></p>';
  28. count++;
  29. });
  30.  
  31. var $tweets = $("#tweets");
  32.  
  33. if (html == '') {
  34. html = '<p>There are no tweets.</p>';
  35. }
  36.  
  37. $tweets.append(html);
  38.  
  39. };
  40.  
  41. $.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + handle + "&count=200&callback=?",JSONCallback);
  42. }

Report this snippet  

You need to login to post a comment.