33
Twitter & OAuth 101 What’s this twit all about? Andy Badera (@andrewbadera) [email protected] http://blog.badera.us/ TVUG October 2009

Twitter API & OAuth 101 TVUG October 2009

Embed Size (px)

Citation preview

Page 1: Twitter API & OAuth 101 TVUG October 2009

Twitter & OAuth 101What’s this twit all about?

Andy Badera (@andrewbadera)[email protected]

http://blog.badera.us/TVUG October 2009

Page 2: Twitter API & OAuth 101 TVUG October 2009

Background

Page 3: Twitter API & OAuth 101 TVUG October 2009

The Numbers

79.7M users as of October 4th (all inclusive; ~50M “official”)

$153M in funding as of end of September

28,000+ applications

30,000+ developers

$23M+ invested in third party app startups

Page 4: Twitter API & OAuth 101 TVUG October 2009

Growth April 2008-2009

Via TechCrunch

Page 5: Twitter API & OAuth 101 TVUG October 2009

APIs

REST API

Search API

Streaming API

Page 6: Twitter API & OAuth 101 TVUG October 2009

REST API

api.twitter.com

Returns: XML, JSON, RSS, ATOM

Read timelines

Send tweets

Read/send Direct Messages

Page 7: Twitter API & OAuth 101 TVUG October 2009

Search API

http://search.twitter.com/

Returns: JSON, ATOM

Trends

Terms (“from:andrewbadera”)

Geolocation (“near:albany within:5miles”)

Page 8: Twitter API & OAuth 101 TVUG October 2009

New Stuff

Geolocation (improved)

Group Lists

Retweet API

Address Book

Apple Push

Search API cleanup

Page 9: Twitter API & OAuth 101 TVUG October 2009

Fab Four

Page 10: Twitter API & OAuth 101 TVUG October 2009

Platform Team?

Page 11: Twitter API & OAuth 101 TVUG October 2009

Trademark Controversy

Page 12: Twitter API & OAuth 101 TVUG October 2009

What’s safe to use?

Avoid “Twitter”

Avoid bird graphics

Avoid similar UI

Biz sez: “Use ‘tweet.’”

Page 13: Twitter API & OAuth 101 TVUG October 2009

Goals

Register a new OAuth application

Retrieve timelines

Send Tweets

Send/Receive Direct Messages

Query Search API

Page 14: Twitter API & OAuth 101 TVUG October 2009

.NET & Twitter

Expect-100 Continue (HttpWebRequest) Request.ServicePoint.Expect100Continue = false;

302 Redirects if ( response.StatusCode == HttpStatusCode.Redirect ) { this.Url = new Uri( uri, response.Headers["Location"] ).ToString(); this.CookieContainer.Add( response.Cookies ); }

64-bit IDs (ulong - Convert.ToUInt64(“”))

LinqToTwitter http://www.codeplex.com/LinqToTwitter

Tweetsharp http://code.google.com/p/tweetsharp/

DotNetOpenAuth http://dotnetopenauth.net:8000/

Page 15: Twitter API & OAuth 101 TVUG October 2009

RateLimit

Ratelimit: 150 REST GETs/hour

X-RateLimitX-RateLimit-RemainingX-RateLimit

Whitelisted: 20000

Page 16: Twitter API & OAuth 101 TVUG October 2009

Whitelisting

http://twitter.com/help/request_whitelisting

Turnaround time

Page 17: Twitter API & OAuth 101 TVUG October 2009

In the beginning, HTTP Basic

HTTP Basic Authorization

Simple

Familiar

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Page 18: Twitter API & OAuth 101 TVUG October 2009

Basic Auth Pulls a Fail Whale

Page 19: Twitter API & OAuth 101 TVUG October 2009

Downsides of HTTP Basic Auth

Base64(byte[] “username:password”)

Giving credentials away to third parties

Password change

Trust

Rate limit by application IP

Page 20: Twitter API & OAuth 101 TVUG October 2009

O-wot?

Secure API authorization

Blaine Cook (Twitter)

Chris Messina (Ma.gnolia)

Currently: OAuth 1.0A

OAuth.net

Shannon Whitley’s OAuthBase.cs

Page 21: Twitter API & OAuth 101 TVUG October 2009

How OAuth Works

Shared secret

Nonce

Timestamp

Page 22: Twitter API & OAuth 101 TVUG October 2009

OAuth & Twitter

Moves burden of ratelimit to user account

Read/write (typical)

Sign-in with Twitter

“Guns for cash” – one time auth

Page 23: Twitter API & OAuth 101 TVUG October 2009

Timelines

Page 24: Twitter API & OAuth 101 TVUG October 2009

That’s cool, but …

Page 25: Twitter API & OAuth 101 TVUG October 2009

Real-time Search

User-Agent!

Page 26: Twitter API & OAuth 101 TVUG October 2009

Common OAuth Gotchas

Page 27: Twitter API & OAuth 101 TVUG October 2009

Technical

Parameter sorting

Parameter URL encoding

Server clock

Page 28: Twitter API & OAuth 101 TVUG October 2009

Social

OAuth is not a panacea!

Use common sense!

Page 29: Twitter API & OAuth 101 TVUG October 2009

OAuth Best Practice

“As with OpenID, OAuth is difficult to implement correctly and securely.  Pick a good, dependable library to take a dependency on instead.”

--Andrew ArnottDotNetOpenAuth Authorvia email

Page 30: Twitter API & OAuth 101 TVUG October 2009

Q&A

Thanks for your time.

Any questions?

Page 31: Twitter API & OAuth 101 TVUG October 2009

Drinks!

JJ Rafferty’s

Route 9

North of Latham Traffic Circle on right

Next to Price Chopper parking lot

Across from Red Robin

Page 32: Twitter API & OAuth 101 TVUG October 2009

Bibliography

Alex Payne slideshare presentation: “Twitter API 2.0”, http://www.slideshare.net/al3x/twitter-api-20

Mashable: “Twitter’s Value: 5 Eye-popping Stats”, http://mashable.com/2009/10/04/twitter-stats/

Biz Stone blog entry: “May the Tweets Be With You” http://blog.twitter.com/2009/07/may-tweets-be-with-you.html

Page 33: Twitter API & OAuth 101 TVUG October 2009

Resources

Twitter API docs http://apiwiki.twitter.com/

Twitter Dev list http://groups.google.com/group/twitter-development-talk

API blog http://apiblog.twitter.com/ (not well updated)

@andrewbadera (http://twitter.com/andrewbadera)

http://blog.badera.us/

[email protected]