2. What is Twitter?
Twitter is simple
Subscribes to
philosophy, “Do one
thing and do it well”
Lets you share and
discuss your thoughts
through a community
you design
3. How is it used?
Have something to share? Send out a tweet.
Should be easy, seamless, ubiquitous
Any device (phone, tablet,
PC...)
Any method (web, app,
SMS...)
Tweets are your thoughts.
Think them, tweet them!
4. But wait!
Isn’t Twitter a website? Facebook is a
website...
You’re thinking too small
Twitter is a mode of communication!
Talking, writing, calling, emailing,
texting, and now, tweeting
Each has its own purpose, properties, and place
5. There’s just one problem...
Twitter is a web service
Tweets travel from you to your followers over the
good 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)
8. The Internet is everywhere
More and more people have access to the Internet
wherever they go
From their desk
From their lap
From their phone, on the go
Always on, always there
Most people take this very fact for granted
9. Ubiquity
So I think I see what
you mean
With the ubiquity of
the web, a web
service becomes a
viable form of
communication...
...not constrained by
any context
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 I
need a website to use it?
12. The Internet is everywhere
Again, you’re thinking too small
Twitter uses the Internet to work
But to the user, with ubiquitous web access, this is
just a minor implementation detail
No one really cares how calls work, or how texts
work, or even how talking works
They just want them to work
13. The Internet is everywhere
But the user does care about one
thing:
How to interact with the device to
use the service
Some sort of interface is
required
But not just any
Different form factors call for
different interfaces
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 interaction
How do we solve this problem?
16. What is an API?
API stands for “Application Programming Interface”
It’s an interface for your interface
How does a user interact with an application?
Through its user interface
How does the application interact with a service?
Through an API
17. Too good to be true?
So Twitter lets you access and act on all the data
hosted by the service?
For the most part, yes
You just choose how you want to use it
But does it really work well?
You be the judge
Twitter certainly thinks it does...
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
20. Let’s get started
We’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”
21. Hello, Twitter API
Let’s make our first API call to get the public
timeline
You’ve probably used a UNIX-like terminal on your
computer
For some people, it’s all they use
Fire it up, and run the following command:
curl http://twitter.com/statuses/
public_timeline.rss
22. Hello, Twitter API
Neat!
Almost instantaneously, we’re presented with the
public timeline in beautiful XML
Let’s try something else
curl -u username:password http://
twitter.com/statuses/
friends_timeline.xml
Oops...
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?
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
28. App Registration
OAuth is a little more “legit”
Want your application to access
Twitter?
You’ll have to register it first
Let’s do this now
Hit up http://twitter.com/
apps/new
I’ll walk you through
29. Consumer Key and Secret
Alright, we’ve registered our app
Let’s look at some of the information Twitter has
provided us about it
We’ll focus on two, which we use to sign our
requests to Twitter
Consumer Key
Consumer Secret
30. Getting a Request Token
So far so good
The script that gets are request token is
getreqtok.php
So let’s run it via the Terminal
cd /path/to/the/folder
php getreqtok.php
Did it work?
31. Getting a Request Token
What did we get?
A request token...
...and its accompanying secret
Plus an authorization URL
So copy that URL and allow your new Twitter client
to access your Twitter account
32. OAuth Verification
This should give you an OAuth verification number
Copy it down...
...and enter it into getacctok.php
What else do we need here?
Our request token and secret
Now run the script
Here’s your access token!
33. Access Token
That’s it!
Really
Save this token somewhere, and you’re
authenticated for good
So how do we use it?
Just include it with every API call you make
Speaking of API calls, let’s try one
34. Making an API Call
Let’s pick something simple
Let’s try posting a tweet
Got our access token? Good
Open 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. Posting a Tweet
We’re almost there!
Change $tweet to the tweet you want to send
And just run the script
php tweet.php
Now refresh your Twitter account (using an
interface of your choosing..), and...
38. Onwards
We’ve just scratched the surface
Practically anything you can think
of, you can do with the API
Go crazy!
But read the documentation first
(it’s good)
http://dev.twitter.com/doc
39. Onwards
How can you go on from here?
Try out the different API calls
Timeline
User timeline
User info
Favorite tweets
Direct messages
40. Onwards
Or 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. Case Study: Birdfeed
I’m using the Twitter API
myself
The iPhone has some great
Twitter apps
But I think I can come up
with something better
43. MGTwitterEngine
iPhone applications are written
in Cocoa, a framework usually
used with Objective-C
With Cocoa, using the Twitter
API directly is a bit unruly
With the open source
MGTwitterEngine, developed by
Matt Gemmell, you get a natural,
Cocoa-like way to use the API
44. MGTwitterEngine
The OAuth token flow works
almost exactly the same
But uses an interface within the
app for logging in
Once the user logs in, the token is
retrieved behind the scenes
The token is saved, and that’s it
for authentication
45. MGTwitterEngine
All of the API calls are performed
with a traditional Cocoa message
passing syntax to an instance of
your Twitter engine
For example, this will return a list
of tweets from the user’s home
timeline, ready to be displayed
46. Case Study: Birdfeed
Birdfeed is all about creating the best designed
Twitter 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
47. Case Study: Birdfeed
What’s cool about this?
Ironically, the Twitter API was written in such a way
that using it is what I care about the least
The high level of abstraction lets me not even think
about how I’m interacting with data
Instead, gives me full focus on creating a user
experience I think people will really love.
48. What will you do with the
Twitter API?
Something important, say...