75
YQL, Flickr, OAuth, YAP Erik Eldridge Yahoo! Developer Network 3/31/09 Photo credit: Marco Bellucci((http://ow.ly/1M0c)

YQL, Flickr, OAuth, YAP

Embed Size (px)

DESCRIPTION

A presentation for IDC - 3/31/09 - Israel

Citation preview

Page 1: YQL, Flickr, OAuth, YAP

YQL, Flickr, OAuth, YAP

Erik Eldridge

Yahoo! Developer Network

3/31/09Photo credit: Marco Bellucci((http://ow.ly/1M0c)

Page 2: YQL, Flickr, OAuth, YAP

Follow along (or skip ahead)

• http://slideshare.net/erikeldridge

Page 3: YQL, Flickr, OAuth, YAP

YQL

Page 4: YQL, Flickr, OAuth, YAP

YQL is select * from internet

• Allows you to quickly & simply mashup data from Yahoo! and elsewhere

• Programmatic SQL-like language

• Successor to Yahoo! Pipes

Page 5: YQL, Flickr, OAuth, YAP

YQL on YDN

Page 6: YQL, Flickr, OAuth, YAP

YQL console

Page 7: YQL, Flickr, OAuth, YAP

BOSS-like search

Page 8: YQL, Flickr, OAuth, YAP

Public data

Page 9: YQL, Flickr, OAuth, YAP

YQL proxy & frontend

Page 10: YQL, Flickr, OAuth, YAP

YQL trogdor

Page 11: YQL, Flickr, OAuth, YAP

HTML to extract

Page 12: YQL, Flickr, OAuth, YAP

HTML extraction in console

Page 13: YQL, Flickr, OAuth, YAP

HTML extraction code

Page 14: YQL, Flickr, OAuth, YAP

RSS extraction

Page 15: YQL, Flickr, OAuth, YAP

RSS raw

Page 16: YQL, Flickr, OAuth, YAP

RSS extraction in console

Page 17: YQL, Flickr, OAuth, YAP

RSS extraction code

Page 18: YQL, Flickr, OAuth, YAP

RSS extracted

Page 19: YQL, Flickr, OAuth, YAP

YQL Open Tables

Page 20: YQL, Flickr, OAuth, YAP

Open table examples

Page 21: YQL, Flickr, OAuth, YAP

Twitter status Open Table

Page 22: YQL, Flickr, OAuth, YAP

Twitter status table raw

Page 23: YQL, Flickr, OAuth, YAP

Twitter status Open Table in action

Page 24: YQL, Flickr, OAuth, YAP

Resources

• YQL:http://developer.yahoo.com/yql

• Open Table examples: http://github.com/spullara/yql-tables/tree/master

• PHP:http://php.net

Page 25: YQL, Flickr, OAuth, YAP

Flickr

Page 26: YQL, Flickr, OAuth, YAP

Flickr homepage

Page 27: YQL, Flickr, OAuth, YAP

Flickr API page

Page 28: YQL, Flickr, OAuth, YAP

Use YQL for public pics

Page 29: YQL, Flickr, OAuth, YAP

Desc flickr.photos.search

Page 30: YQL, Flickr, OAuth, YAP

Resolve Flickr username

Page 31: YQL, Flickr, OAuth, YAP

Request user’s photos in YQL

Page 32: YQL, Flickr, OAuth, YAP

Use proxy to get data

Page 33: YQL, Flickr, OAuth, YAP

Catch the data in the client

Page 34: YQL, Flickr, OAuth, YAP

Output

Page 35: YQL, Flickr, OAuth, YAP

Flickr API endpoint

Page 36: YQL, Flickr, OAuth, YAP

Flickr API explorer

Page 37: YQL, Flickr, OAuth, YAP

Flickr Auth: fetching frob

Page 38: YQL, Flickr, OAuth, YAP

Flickr auth: fetching token

Page 39: YQL, Flickr, OAuth, YAP

Flickr auth: making request

Page 40: YQL, Flickr, OAuth, YAP

Resources

• Flickr APIs:http://www.flickr.com/services/api/

Page 41: YQL, Flickr, OAuth, YAP

OAuth

Page 42: YQL, Flickr, OAuth, YAP

Overview

• What is OAuth?

• In general, how do I use it?

• Getting started with Oauth on Yahoo!

Page 43: YQL, Flickr, OAuth, YAP

OAuth is an open protocol

• Allows developers to safely access a user’s private data

• Similar to OpenID• Used to secure HTTP requests• Credentials given only to trusted sites• Open alternative to proprietary protocols

– Google’s AuthSub– AOL’s OpenAuth– Yahoo’s BBAuth and FlickrAuth– Facebook’s FacebookAuth

Page 44: YQL, Flickr, OAuth, YAP

How does a developer use it?

1. Fetch a request token

2. Redirect user to authorize with request token

3. Fetch and store an access token

4. Make signed API requests

Page 45: YQL, Flickr, OAuth, YAP

For the visually-inclinedYour App (the consumer) API (Oauth provider)

Your App APIAccess token

Your App APISigned request

The user APIAuthorization

Your App APIRequest token

Fetch request token

Page 46: YQL, Flickr, OAuth, YAP

Yahoo! Oauth diagram

http://ow.ly/1KuX

Page 47: YQL, Flickr, OAuth, YAP

How to get a Yahoo! Oauth API key and secret

Page 48: YQL, Flickr, OAuth, YAP

The YDN registration form

• be sure to:– Select “Web-based” from the drop-down if

you want to make a web app– Request access to “private user data” if

you need social data in your app

Page 49: YQL, Flickr, OAuth, YAP

Successful registration

• Shows the key and secret used for signing a request

Page 50: YQL, Flickr, OAuth, YAP

Domain verification

• For web-based apps, you will need to verify that you own the domain that will be hosting your app

Page 51: YQL, Flickr, OAuth, YAP

The easiest way to get started is with the Yahoo! PHP SDK

<?phprequire('yosdk/lib/Yahoo.inc');

$key = 'dj0yJmk9b25tMTdCb3NndVc3JmQ9WVdrOWRFRlFXbFJqTkRnbWNHbzlNakV6TmpNMU16TTUmcz1jb25zdW1lcnNlY3JldCZ4PWQ4';

$secret = 'ccb100d2ddd70c90e999055311b714db17a35029';$app_id = 'tAPZTc48';

$session = YahooSession::requireSession($key, $secret, $app_id);$user = $session->getSessionedUser();

$title = ' installed this OAuth app';$link = 'http://example.erikeldridge.com/oauth/';$suid = 'update'.time();

$user->insertUpdate($suid, $title, $link);

Page 52: YQL, Flickr, OAuth, YAP

An example update on the Yahoo! profile page

Page 53: YQL, Flickr, OAuth, YAP

App Updates

Updates are distributed across Yahoo! and beyond• Properties, e.g., Mail, Profiles, Buzz, etc.• Clients, e.g., Messenger, Toolbar• Externally through Updates API

Page 54: YQL, Flickr, OAuth, YAP
Page 55: YQL, Flickr, OAuth, YAP

The next easiest way is to use one of the freely available

libraries

Page 56: YQL, Flickr, OAuth, YAP

Fetching request token without the Yahoo! PHP SDK

<?php$key =

'dj0yJmk9b25tMTdCb3NndVc3JmQ9WVdrOWRFRlFXbFJqTkRnbWNHbzlNakV6TmpNMU16TTUmcz1jb25zdW1lcnNlY3JldCZ4PWQ4';$secret = 'ccb100d2ddd70c90e999055311b714db17a35029'; require('yosdk/lib/OAuth.php'); $consumer = new OAuthConsumer($key, $secret);//key/secret from Y!$url = 'https://api.login.yahoo.com/oauth/v2/get_request_token';$request = OAuthRequest::from_consumer_and_token($consumer, NULL, 'POST', $url, array());$request->sign_request(new OAuthSignatureMethod_PLAINTEXT(), $consumer, NULL); $ch = curl_init($url);$options = array(

CURLOPT_POSTFIELDS => $request->to_postdata(),CURLOPT_RETURNTRANSFER => true

);curl_setopt_array($ch, $options);parse_str(curl_exec($ch), $resp);curl_close($ch); $requestToken = new stdclass();$requestToken->key = $resp["oauth_token"];$requestToken->secret = $resp["oauth_token_secret"]; file_put_contents('token.txt', json_encode($requestToken));$url = sprintf("https://%s/oauth/v2/request_auth?oauth_token=%s",

'api.login.yahoo.com', urlencode($requestToken->key)

);echo “go here & authorize: $url”;

Page 57: YQL, Flickr, OAuth, YAP

Fetching the access token without the Yahoo! PHP SDK,

part 1

$key = 'dj0yJmk9b25tMTdCb3NndVc3JmQ9WVdrOWRFRlFXbFJqTkRnbWNHbzlNakV6TmpNMU16TTUmcz1jb25zdW1lcnNlY3JldCZ4PWQ4';

$secret = 'ccb100d2ddd70c90e999055311b714db17a35029';$app_id = 'tAPZTc48';require('yosdk/OAuth.php');$consumer = new OAuthConsumer(KEY, SECRET);$requestToken = json_decode(file_get_contents('token.txt')); $url = 'https://api.login.yahoo.com/oauth/v2/get_token';$request = OAuthRequest::from_consumer_and_token($consumer, $requestToken, 'POST', $url, array());$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $requestToken);$headers = array(

"Accept: application/json");$ch = curl_init($url);$options = array( CURLOPT_POST=> true,

CURLOPT_POSTFIELDS => $request->to_postdata(),CURLOPT_RETURNTRANSFER => true

);curl_setopt_array($ch, $options);parse_str(curl_exec($ch), $response); curl_close($ch);

Page 58: YQL, Flickr, OAuth, YAP

Fetching the access token without the Yahoo! PHP SDK,

part 2

$now = time();$accessToken = new stdclass();$accessToken->key = $response["oauth_token"];$accessToken->secret = $response["oauth_token_secret"];$accessToken->guid = $response["xoauth_yahoo_guid"];$accessToken->consumer = $consumer;$accessToken->sessionHandle = $response["oauth_session_handle"];if(array_key_exists("oauth_expires_in", $response)) { $accessToken->tokenExpires = $now + $response["oauth_expires_in"];}else { $accessToken->tokenExpires = -1;}if(array_key_exists("oauth_authorization_expires_in", $response)) { $accessToken->handleExpires = $now + $response["oauth_authorization_expires_in"];}else { $accessToken->handleExpires = -1;}file_put_contents('token.txt', json_encode($accessToken));

Page 59: YQL, Flickr, OAuth, YAP

Making a signed request to Updates API without the Yahoo! PHP SDK, part 1

$guid = $response["xoauth_yahoo_guid"];$title = 'Confirmation update';//arbitrary title$description = 'The time is now '.date("g:i a");//arbitrary desc$link = sprintf('http://%s/oauth/', ‘example.erikeldridge.com/oauth’);//arbitrary link$source = ’APP.'.$app_id;//note: 'APP.' syntax$date = time();$suid = ’update'.time();//arbitrary, unique string$body = array(

"updates" => array(array(

"collectionID" => $guid,"collectionType" => "guid","class" => "app","source" => $source,"type" => 'appActivity',"suid" => $suid,"title" => $title,"description" => $description,"link" => $link,"pubDate" => (string)$date

))

);

Page 60: YQL, Flickr, OAuth, YAP

Making a signed request to Updates API without the Yahoo! PHP SDK, part 2

$url = sprintf("http://%s/v1/user/%s/updates/%s/%s",'social.yahooapis.com', $guid, $source, urlencode($suid)

);$request = OAuthRequest::from_consumer_and_token(

$consumer, $accessToken, 'PUT', $url, array());

$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),$consumer, $accessToken

);

Page 61: YQL, Flickr, OAuth, YAP

Making a signed request to the Updates API without the

Yahoo! PHP SDK, part 3

$headers = array("Accept: application/json");$headers[] = $request->to_header();$headers[] = "Content-type: application/json";$content = json_encode($body); $ch = curl_init($url);$options = array(

CURLOPT_HTTPHEADER => $headers,CURLOPT_POSTFIELDS => $content,CURLOPT_RETURNTRANSFER => true,CURLOPT_CUSTOMREQUEST => 'PUT',CURLOPT_TIMEOUT => 3

);curl_setopt_array($ch, $options);$resp = curl_exec($ch);curl_close($ch);

Page 62: YQL, Flickr, OAuth, YAP

Resources

• Hueniverse’s introduction:http://www.hueniverse.com/hueniverse/2007/10/beginners-guide.html

• Yahoo!’s Oauth documentation:http://developer.yahoo.com/oauth

• Yahoo! PHP and ActionScript SDKs:http://developer.yahoo.com/social/sdk/

• Google’s OAuth playground:http://googlecodesamples.com/oauth_playground/

Page 63: YQL, Flickr, OAuth, YAP

Yahoo! Application Platform

Page 64: YQL, Flickr, OAuth, YAP

Why is Yahoo! opening up?

• A history of supporting open technology– Apache, MySQL, PHP, JavaScript,

BSD/Linux, to name a few

• A history of hacking

• Yahoo! wants to share its audience

Page 65: YQL, Flickr, OAuth, YAP

What is the Yahoo! Application Platform?

• It’s a way to run apps on Yahoo!

Page 66: YQL, Flickr, OAuth, YAP

3 views of YAP: My Y! screenshot

Page 67: YQL, Flickr, OAuth, YAP

3 views of YAP: canvas screenshot

Page 68: YQL, Flickr, OAuth, YAP

3 views of YAP: y! metro

Page 69: YQL, Flickr, OAuth, YAP

Yahoo! Application Platform (YAP)

• Optimized for speed and security (YML, Caja)• Uses raw Javascript, CSS, and HTML, and

Yahoo! Markup Language (YML)• Supports OpenSocial JavaScript API

Page 70: YQL, Flickr, OAuth, YAP

How do I use it?

YDN key/secret

+

Your server

+

Your code

=

Your app on Yahoo!

Page 71: YQL, Flickr, OAuth, YAP

Example: OpenSocial Activities

<script>var params = {};params[opensocial.Activity.Field.TITLE] = 'title';params[opensocial.Activity.Field.BODY] = 'body';

var activity = opensocial.newActivity(params);

opensocial.requestCreateActivity(activity,opensocial.CreateActivityPriority.LOW,function(){});

</script>

Page 72: YQL, Flickr, OAuth, YAP

Example: Screenshot of results

Page 73: YQL, Flickr, OAuth, YAP

What does YAP do for me?

• Hundreds of millions of Yahoo! users

• Instant publication

• Secure, Standard JavaScript, HTML, CSS

• OpenSocial JS API

Page 75: YQL, Flickr, OAuth, YAP

תודה!Thank you!

• Find me on slideshare, twitter and github @erikeldridge