locovore
DESCRIPTION
round 2TRANSCRIPT
Katherine Lee | Internet Applications
Using ’s API with PHP
beta
Concept: using Twitter’s API and a PHP site to retrieve and store mobile location and message in a database
On my way to the library, where my wildest dreams are going to come true today
• OAuth is an authentication protocol through which a user may allow an application to perform some action on their behalf without sharing their password
• The important thing is that it’s a standardized way of granting secure API access to user accounts
cURL: How the API communicates with PHP
function http($url, $post_data = null) {/*{{{*/ $ch = curl_init(); if (defined("CURL_CA_BUNDLE_PATH")) curl_setopt($ch, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); ////////////////////////////////////////////////// ///// Set to 1 to verify Twitter's SSL Cert ////// ////////////////////////////////////////////////// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); if (isset($post_data)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } $response = curl_exec($ch); $this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $this->last_api_call = $url; curl_close ($ch); return $response;
How Twitter OAuth works• You register your application with Twitter, specifying a callback URL• Twitter gives you:
1. Consumer key2. Consumer secret3. Request token URL4. Access token URL5. Authorize URL
• Consumer key+secret initiate a conversation with Twitter• If the key+secret are validated by Twitter, Twitter’s request token
allows you to send the user to an authorize URL• If the user grants your application permission, Twitter sends the
user to your callback URL
Info I can pull on the User
• Full name• Twitter username• Location (longitude/latitude only for GPS or iPhone
enabled devices)• Photo icon• Date joined Twitter network• Date/Time/Message in last tweet
Locovore demo
Issues
• Lack of standardization in mobile location capability in devices• Twitterific (and apps like it) are only for iPhone or GPS-
supporting devices• Google Latitude only supported by:
– Android-powered devices– Most color Blackberry devices– Most Windows Mobile 5.0+ devices– Most Symbian S60 devices
• Too bad if you don’t have GPS – your Google MyLocation will be inaccurate and is only supported on some Motorola and Sony Erickson devices outside of those devices supported by Google Latitude
Future
• Better, more universal location standards for mobile use
• See only local tweets within a very small radius of wherever you happen to be
Thanks
Code based on William Abraham’s:• Fire Eagle code -
http://github.com/myelin/fireeagle-php-lib• twitterlibphp -
http://github.com/poseurtech/twitterlibphp