Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TwitterLib.js

4,252 views

Published on

A walk through of the features of TwitterLib.js - a library that helps standardise all the Twitter API calls and all the data coming back from Twitter, and includes a collection of utility methods to speed development up.

Published in: Technology

TwitterLib.js

  1. 1. TwitterLib.js
  2. 2. What is it?
  3. 3. Why?
  4. 4. http://github.com/remy/twitterlib
  5. 5. Examples
  6. 6. Features
  7. 7. Features •Consistent interface & data structure •Support for custom APIs •Automatic paging •Included utilities: •ify, render, time
  8. 8. API
  9. 9. timeline status favs search list
  10. 10. <script src="twitterlib.js"></script>
  11. 11. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.timeline('rem', function (data) { }); </script>
  12. 12. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.timeline('rem', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(data[i].text); } }); </script>
  13. 13. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.timeline('rem', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(twitterlib.render(data[i])); } }); </script>
  14. 14. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.timeline('rem', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(twitterlib.render(data[i])); } tweets.innerHTML = html.join(''); }); </script>
  15. 15. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.status('rem', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(twitterlib.render(data[i])); } tweets.innerHTML = html.join(''); }); </script>
  16. 16. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.favs('rem', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(twitterlib.render(data[i])); } tweets.innerHTML = html.join(''); }); </script>
  17. 17. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.list('rem/local', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(twitterlib.render(data[i])); } tweets.innerHTML = html.join(''); }); </script>
  18. 18. <script src="twitterlib.js"></script> <script> var tweets = document.getElementById('tweets'); twitterlib.search('@rem', function (data) { var html = []; for (var i = 0; i < data.length; i++) { html.push(twitterlib.render(data[i])); } tweets.innerHTML = html.join(''); }); </script>
  19. 19. Options
  20. 20. Options twitterlib.timeline('rem', fn); twitterlib.timeline('rem', {/*options*/}, fn);
  21. 21. Options • page: 1 • limit: 200 • since_id: 1 • filter: 'foo'
  22. 22. Options twitterlib.timeline( 'rem', { since_id: 123, filter: 'foo' }, fn );
  23. 23. Filter
  24. 24. Filter foo
  25. 25. Filter foo foo bar (foo and bar)
  26. 26. Filter foo foo bar (foo and bar) foo OR bar
  27. 27. Filter foo foo bar (foo and bar) foo OR bar "foo bar" (atomic string)
  28. 28. Filter foo foo bar (foo and bar) foo OR bar "foo bar" (atomic string) foo -bar (foo, not bar)
  29. 29. Filter foo foo bar (foo and bar) foo OR bar "foo bar" (atomic string) foo -bar (foo, not bar) from:rem foo
  30. 30. Filter foo foo bar (foo and bar) foo OR bar "foo bar" (atomic string) foo -bar (foo, not bar) from:rem foo to:rem foo
  31. 31. Utilities
  32. 32. Utilities .custom(name, url)
  33. 33. Utilities twitterlib.custom('dm', '/tweets?page=%page%&type=dm'); twitterlib.dm(callback);
  34. 34. Utilities .next()
  35. 35. Utilities var html = []; twitterlib.timeline('rem', {limit: 5}, function(tweets){ for (var i = 0; i < tweets.length; i++) { html.push(this.render(tweets[i])); } })
  36. 36. Utilities var html = []; twitterlib.timeline('rem', {limit: 5}, function(tweets){ for (var i = 0; i < tweets.length; i++) { html.push(this.render(tweets[i])); } }).next();
  37. 37. Utilities .render(tweet)
  38. 38. Utilities .ify.clean(text)
  39. 39. Utilities List of Twitter developers in the @WiredUK photo: @nuxnix/uk- twitterati #devnest: http://www.wired.co.uk/wired-magazine/ archive/2009/12/start/wired%27s-guide-to-the-uk-twitterati.aspx List of Twitter developers in the @WiredUK photo: @nuxnix/uk-twitterati #devnest: http://www.wired.co.uk/w...
  40. 40. Utilities .time.relative(t)
  41. 41. Utilities Fri Jan 08 15:44:49 +0000 2010 20 minutes ago
  42. 42. Photos by Balakov Enjoy. @rem http://j.mp/dnfeb

×