Jordan Kay's Twitter API tour


Published on

Jordan Kay (jordanekay)'s Twitter API guided tour for PennApps 2010.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Jordan Kay's Twitter API tour

  1. 1. The Twitter API A Brief Tour Pe nnApps 2010
  2. 2. What is Twitter?Twitter is simpleSubscribes tophilosophy, “Do onething and do it well”Lets you share anddiscuss your thoughtsthrough a communityyou design
  3. 3. How is it used?Have something to share? Send out a tweet.Should be easy, seamless, ubiquitousAny device (phone, tablet,PC...)Any method (web, app,SMS...)Tweets are your thoughts.Think them, tweet them!
  4. 4. But wait!Isn’t Twitter a website? Facebook is awebsite...You’re thinking too smallTwitter is a mode of communication!Talking, writing, calling, emailing,texting, and now, tweetingEach has its own purpose, properties, and place
  5. 5. There’s just one problem...Twitter is a web serviceTweets travel from you to your followers over thegood old World Wide Web Not through paper Not through your voice But through your very own, personal Internets Or whatever you decide to call it (not a truck)
  6. 6. So doesn’t this compromise its availability?
  7. 7. No.
  8. 8. The Internet is everywhereMore and more people have access to the Internetwherever they go From their desk From their lap From their phone, on the goAlways on, always there Most people take this very fact for granted
  9. 9. UbiquitySo I think I see whatyou meanWith the ubiquity ofthe web, a webservice becomes aviable form ofcommunication......not constrained byany context
  10. 10. Ubiquity Still, something’s off here... I can access the web from anywhere, sure But is logging on to a website the best way to share my thoughts?How can Twitter be so natural and seamless if Ineed a website to use it?
  11. 11. Answer: You don’t.
  12. 12. The Internet is everywhereAgain, you’re thinking too smallTwitter uses the Internet to workBut to the user, with ubiquitous web access, this isjust a minor implementation detailNo one really cares how calls work, or how textswork, or even how talking worksThey just want them to work
  13. 13. The Internet is everywhereBut the user does care about onething:How to interact with the device touse the service Some sort of interface is required But not just any Different form factors call for different interfaces
  14. 14. Ubiquity So the Twitter service itself must be interface agnostic The data itself must be ubiquitous Same data, same ways to use it, through any method of interactionHow do we solve this problem?
  15. 15. Enter the Twitter API.
  16. 16. What is an API?API stands for “Application Programming Interface”It’s an interface for your interfaceHow does a user interact with an application? Through its user interfaceHow does the application interact with a service? Through an API
  17. 17. Too good to be true?So Twitter lets you access and act on all the datahosted by the service? For the most part, yes You just choose how you want to use itBut does it really work well? You be the judge Twitter certainly thinks it does...
  18. 18. Sounds great! I want to take it for a spin I want to build on top of Twitter What cool things can I do with it? Integrate Twitter into your app... ...or your site... ...or your device
  19. 19. Let’s get started.
  20. 20. Let’s get startedWe’ll start with something simple The public timeline, accessible to anyone If this is your first exposure to Twitter, it gets better, I promise Most of this stuff is useless... ...but so is “Hello World”
  21. 21. Hello, Twitter APILet’s make our first API call to get the publictimelineYou’ve probably used a UNIX-like terminal on yourcomputer For some people, it’s all they useFire it up, and run the following command: curl public_timeline.rss
  22. 22. Hello, Twitter APINeat!Almost instantaneously, we’re presented with thepublic timeline in beautiful XMLLet’s try something elsecurl -u username:password
  23. 23. It’s not that easy...This used to work......but there were some downsides Left user credentials exposed Limited in number of requests And what if the user changes his password... ...or changes his mind about the app?Why not something better?
  24. 24. Enter OAuth.
  25. 25. What is OAuth? Stands for “Open Authorization” Uses tokens instead of credentials Once you request a token with your credentials, you’re good to go It’s that easy
  26. 26. But the implementation is abit tricky. So we’ll take our time.
  27. 27. Works like this
  28. 28. App RegistrationOAuth is a little more “legit”Want your application to accessTwitter?You’ll have to register it firstLet’s do this now Hit up apps/new I’ll walk you through
  29. 29. Consumer Key and SecretAlright, we’ve registered our appLet’s look at some of the information Twitter hasprovided us about it We’ll focus on two, which we use to sign our requests to Twitter Consumer Key Consumer Secret
  30. 30. Getting a Request TokenSo far so goodThe script that gets are request token isgetreqtok.phpSo let’s run it via the Terminal cd /path/to/the/folder php getreqtok.phpDid it work?
  31. 31. Getting a Request TokenWhat did we get? A request token... ...and its accompanying secret Plus an authorization URLSo copy that URL and allow your new Twitter clientto access your Twitter account
  32. 32. OAuth VerificationThis should give you an OAuth verification number Copy it down... ...and enter it into getacctok.phpWhat else do we need here? Our request token and secretNow run the scriptHere’s your access token!
  33. 33. Access TokenThat’s it!ReallySave this token somewhere, and you’reauthenticated for goodSo how do we use it? Just include it with every API call you make Speaking of API calls, let’s try one
  34. 34. Making an API CallLet’s pick something simpleLet’s try posting a tweetGot our access token? GoodOpen up tweet.php and find the API call statuses/update in post_tweet We’ll have to send our token along with every call Input your access token and its secret at the top
  35. 35. Posting a TweetWe’re almost there!Change $tweet to the tweet you want to sendAnd just run the script php tweet.phpNow refresh your Twitter account (using aninterface of your choosing..), and...
  36. 36. Voilà!
  37. 37. That wasn’t so bad!
  38. 38. OnwardsWe’ve just scratched the surfacePractically anything you can thinkof, you can do with the APIGo crazy!But read the documentation first(it’s good)
  39. 39. OnwardsHow can you go on from here?Try out the different API calls Timeline User timeline User info Favorite tweets Direct messages
  40. 40. OnwardsOr try out different interfaces and form factors Something like what we’ve done using PHP would be great for a web app But what about a desktop client? Or a phone client? The API’s got you covered
  41. 41. Case Study: BirdfeedI’m using the Twitter APImyselfThe iPhone has some greatTwitter appsBut I think I can come upwith something better
  42. 42. Enter Birdfeed.
  43. 43. MGTwitterEngineiPhone applications are writtenin Cocoa, a framework usuallyused with Objective-CWith Cocoa, using the TwitterAPI directly is a bit unrulyWith the open sourceMGTwitterEngine, developed byMatt Gemmell, you get a natural,Cocoa-like way to use the API
  44. 44. MGTwitterEngineThe OAuth token flow worksalmost exactly the same But uses an interface within the app for logging inOnce the user logs in, the token isretrieved behind the scenesThe token is saved, and that’s itfor authentication
  45. 45. MGTwitterEngineAll of the API calls are performedwith a traditional Cocoa messagepassing syntax to an instance ofyour Twitter engineFor example, this will return a listof tweets from the user’s hometimeline, ready to be displayed
  46. 46. Case Study: BirdfeedBirdfeed is all about creating the best designedTwitter experience on the iPhone“Design isn’t just how it’s how it works.”Ways to make this happen Intuitive, frictionless “pick up and do” interface No meaningless cruft (shortened links, @usernames)Communication is human, and Twitter should be too
  47. 47. Case Study: BirdfeedWhat’s cool about this?Ironically, the Twitter API was written in such a waythat using it is what I care about the leastThe high level of abstraction lets me not even thinkabout how I’m interacting with dataInstead, gives me full focus on creating a userexperience I think people will really love.
  48. 48. What will you do with the Twitter API?Something important, say...
  49. 49. ...winning PennApps?
  50. 50. The end.