What is Twitter?Twitter is simpleSubscribes tophilosophy, “Do onething and do it well”Lets you share anddiscuss your thoughtsthrough a communityyou design
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!
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
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)
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
UbiquitySo I think I see whatyou meanWith the ubiquity ofthe web, a webservice becomes aviable form ofcommunication......not constrained byany context
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?
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
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
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?
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
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...
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
Let’s get startedWe’ll start with something simple The public timeline, accessible to anyone www.twitter.com/public_timeline If this is your first exposure to Twitter, it gets better, I promise Most of this stuff is useless... ...but so is “Hello World”
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 http://twitter.com/statuses/ public_timeline.rss
Hello, Twitter APINeat!Almost instantaneously, we’re presented with thepublic timeline in beautiful XMLLet’s try something elsecurl -u username:password http://twitter.com/statuses/friends_timeline.xmlOops...
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?
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 http://twitter.com/ apps/new I’ll walk you through
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
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?
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
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!
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
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
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...
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) http://dev.twitter.com/doc
OnwardsHow can you go on from here?Try out the different API calls Timeline User timeline User info Favorite tweets Direct messages
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
Case Study: BirdfeedI’m using the Twitter APImyselfThe iPhone has some greatTwitter appsBut I think I can come upwith something better
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
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
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
Case Study: BirdfeedBirdfeed is all about creating the best designedTwitter experience on the iPhone“Design isn’t just how it looks...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
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.
What will you do with the Twitter API?Something important, say...