About MeMy Name is Joel StrellnerI go by @jstrellner on TwitterI’ve been developing things using the Twitter API’s since March, 2008.Twitturly ( http://twitturly.com )inView ( http://myinview.com )
What is an API?An API is a way for any service to allowany other service to programmaticallyaccess and interact with that services data.
What API’s does Twitter offer?Twitter currently offers 3 API’s:REST APIREST Search API (previously Summize)Streaming APIDepreciated API’sData Mining FeedXMPP Feed
REST APIThe REST API is the primary API.Used for:AuthenticationOAuthBasic Auth (depreciated, use OAuth)Posting TweetsGetting your timeline (Tweets from those you follow)Getting your Mentions
Search APISupports all of the same advanced search options that you can do on search.twitter.comGet trending topics by day, week or currentAllows you to consume it in atom and json formatsSupports fuzzy geolocation filteringUses *different* user ID’s than the REST APIWill be eventually the same (V2 of the API’s)
Streaming APIMethods for the Public Stream:Firehose (Not available to most)Gardenhose (large portion of Firehose)Spritzer (small portion of the Firehose)Following Specific Users/TermsBirddog / Shadow / Followmust start with @user or have “in_reply_to” for that userAllows you to follow 200k, 50k or 200 users, respectivelyTrackAllows you to get any tweet matching a keywordDoes not support phrases
What’s being built?Seesmic Desktop  ( http://seesmic.com/ )Uses the REST APIUses the Search APITwitalizer ( http://twitalyzer.com )Uses the Search API (might use the REST API too)inView ( http://myinview.com )Uses the streaming APIYour App?
What’s Coming Next?Geolocation data in each TweetRetweeting (formally)
How do you actually talk to the API?PHP (getting a users timeline):<?php	$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, ‘http://twitter.com/statuses/user_timeline/jstrellner.xml’); curl_setopt ($ch, CURLOPT_USERAGENT, 'Twitturly / v0.6'); curl_setopt ($ch, CURLOPT_HEADER, 0);curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt ($ch, CURLOPT_MAXREDIRS, 10);curl_setopt ($ch, CURLOPT_FAILONERROR, 0);curl_setopt ($ch, CURLOPT_NOSIGNAL, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERPWD, $username . ':' . $password); $result = curl_exec($ch);curl_close ($ch);?>$result now has your response.
( XML Response )
How to send a tweet (Basic Auth)PHP:<?php$msg = ‘this is an example tweet.’;	$curl_handle = curl_init();curl_setopt($curl_handle, CURLOPT_URL, "http:twitter.com/statuses/update.json");curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl_handle, CURLOPT_POST, 1);curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=" . urlencode($msg));curl_setopt($curl_handle, CURLOPT_USERPWD, "$twitter_username:$twitter_password");	$buffer = curl_exec($curl_handle);curl_close($curl_handle);?>$buffer now has your response.
Q&AAny questions, or comments?Feel free to tweet your question using the #tmeetuphashtag.
ResourcesTwitter API Documentationhttp://apiwiki.twitter.com/Twitter-API-DocumentationTwitter Streaming API Documentationhttp://apiwiki.twitter.com/Streaming-API-DocumentationAsk any API Questionhttp://groups.google.com/group/twitter-development-talk

#tmeetup BirdHackers API 101

  • 2.
    About MeMy Nameis Joel StrellnerI go by @jstrellner on TwitterI’ve been developing things using the Twitter API’s since March, 2008.Twitturly ( http://twitturly.com )inView ( http://myinview.com )
  • 3.
    What is anAPI?An API is a way for any service to allowany other service to programmaticallyaccess and interact with that services data.
  • 4.
    What API’s doesTwitter offer?Twitter currently offers 3 API’s:REST APIREST Search API (previously Summize)Streaming APIDepreciated API’sData Mining FeedXMPP Feed
  • 5.
    REST APIThe RESTAPI is the primary API.Used for:AuthenticationOAuthBasic Auth (depreciated, use OAuth)Posting TweetsGetting your timeline (Tweets from those you follow)Getting your Mentions
  • 6.
    Search APISupports allof the same advanced search options that you can do on search.twitter.comGet trending topics by day, week or currentAllows you to consume it in atom and json formatsSupports fuzzy geolocation filteringUses *different* user ID’s than the REST APIWill be eventually the same (V2 of the API’s)
  • 7.
    Streaming APIMethods forthe Public Stream:Firehose (Not available to most)Gardenhose (large portion of Firehose)Spritzer (small portion of the Firehose)Following Specific Users/TermsBirddog / Shadow / Followmust start with @user or have “in_reply_to” for that userAllows you to follow 200k, 50k or 200 users, respectivelyTrackAllows you to get any tweet matching a keywordDoes not support phrases
  • 8.
    What’s being built?SeesmicDesktop ( http://seesmic.com/ )Uses the REST APIUses the Search APITwitalizer ( http://twitalyzer.com )Uses the Search API (might use the REST API too)inView ( http://myinview.com )Uses the streaming APIYour App?
  • 9.
    What’s Coming Next?Geolocationdata in each TweetRetweeting (formally)
  • 10.
    How do youactually talk to the API?PHP (getting a users timeline):<?php $ch = curl_init();curl_setopt ($ch, CURLOPT_URL, ‘http://twitter.com/statuses/user_timeline/jstrellner.xml’); curl_setopt ($ch, CURLOPT_USERAGENT, 'Twitturly / v0.6'); curl_setopt ($ch, CURLOPT_HEADER, 0);curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt ($ch, CURLOPT_MAXREDIRS, 10);curl_setopt ($ch, CURLOPT_FAILONERROR, 0);curl_setopt ($ch, CURLOPT_NOSIGNAL, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERPWD, $username . ':' . $password); $result = curl_exec($ch);curl_close ($ch);?>$result now has your response.
  • 11.
  • 12.
    How to senda tweet (Basic Auth)PHP:<?php$msg = ‘this is an example tweet.’; $curl_handle = curl_init();curl_setopt($curl_handle, CURLOPT_URL, "http:twitter.com/statuses/update.json");curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl_handle, CURLOPT_POST, 1);curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=" . urlencode($msg));curl_setopt($curl_handle, CURLOPT_USERPWD, "$twitter_username:$twitter_password"); $buffer = curl_exec($curl_handle);curl_close($curl_handle);?>$buffer now has your response.
  • 13.
    Q&AAny questions, orcomments?Feel free to tweet your question using the #tmeetuphashtag.
  • 14.
    ResourcesTwitter API Documentationhttp://apiwiki.twitter.com/Twitter-API-DocumentationTwitterStreaming API Documentationhttp://apiwiki.twitter.com/Streaming-API-DocumentationAsk any API Questionhttp://groups.google.com/group/twitter-development-talk

Editor's Notes

  • #5 All of these API’s are available, whether you are developing for the desktop or the web. The Streaming API’s are best suited for web development.
  • #6 Mention that this requires polling Twitter. Also that there are rate limiting methods in place, so you cannot constantly poll for updates.OAuth has two forms currently: a PIN based system, used for mobile apps and Desktop apps, and a standard Twitter login method, used for web based applications.
  • #7 Pull API, you request if from them as you need it.
  • #8 Explain that the streaming API requires a constant connection to Twitter, but you get real-time data. No need to pull.