60

YQL & Yahoo! APIs - Open Hack India 2011

Embed Size (px)

DESCRIPTION

Introduction to YQL & Yahoo! APIs

Citation preview

Page 1: YQL & Yahoo! APIs - Open Hack India 2011
Page 2: YQL & Yahoo! APIs - Open Hack India 2011

YQL AND YAHOO! APIS

Saurabh Sahni YDN Developer, Hacker, Evangelist Twitter: @saurabhsahni

Page 3: YQL & Yahoo! APIs - Open Hack India 2011

Hacking together systems in 24 hours is lot of fun

Page 4: YQL & Yahoo! APIs - Open Hack India 2011

Hacks = Data manipulation

+ Data visualization

Page 5: YQL & Yahoo! APIs - Open Hack India 2011

The web has lot of data around

Page 6: YQL & Yahoo! APIs - Open Hack India 2011

ProgrammableWeb.Com – 3517 APIs

Page 7: YQL & Yahoo! APIs - Open Hack India 2011

Yahoo! has opened up its data

Page 8: YQL & Yahoo! APIs - Open Hack India 2011

http://developer.yahoo.com/everything.html

Page 9: YQL & Yahoo! APIs - Open Hack India 2011

THE TROUBLE WITH DATA •  You need to find data API •  Get Access – Signup for key •  Find data endpoint •  Read docs to learn what parameters you

have •  Get data in obscure format •  Use data after converting and filtering •  More APIs you use, more is your

annoyance

Page 10: YQL & Yahoo! APIs - Open Hack India 2011

To make data access easy on the web, Yahoo! created YQL

Page 11: YQL & Yahoo! APIs - Open Hack India 2011

YQL turns web services and data on the web into databases.

Page 12: YQL & Yahoo! APIs - Open Hack India 2011

select {what} from {where} where {conditions}

Page 13: YQL & Yahoo! APIs - Open Hack India 2011

You can select, filter, sort and limit

Page 14: YQL & Yahoo! APIs - Open Hack India 2011

You can even insert, update and delete from it.

Page 15: YQL & Yahoo! APIs - Open Hack India 2011

FINDING VIDEOS ABOUT BANGALORE

SELECT * FROM youtube.search where query='bangalore'

Page 16: YQL & Yahoo! APIs - Open Hack India 2011

SELECTING PHOTOS OF HACKDAY

SELECT * FROM flickr.photos.search where text="hackday"

Page 17: YQL & Yahoo! APIs - Open Hack India 2011

INSERTING DATA

INSERT INTO bitly.shorten (login, apiKey, longUrl)

VALUES ('ME', 'API_KEY', 'http://yahoo.com')

Page 18: YQL & Yahoo! APIs - Open Hack India 2011

UPDATING DATA

UPDATE social.profile.status

SET status="Using YQL UPDATE”

WHERE guid="NJFIDHVPVVISDX7UKED2WHU"

Page 19: YQL & Yahoo! APIs - Open Hack India 2011

RETRIEVING MY CONTACTS

SELECT * FROM social.contacts WHERE guid=me

Page 20: YQL & Yahoo! APIs - Open Hack India 2011

ACCESSING PRIVATE DATA

http://query.yahooapis.com/v1/yql

Uses OAuth 1.0 for authorization

OAuth is complicated – use one of our SDKs at https://github.com/yahoo

Page 21: YQL & Yahoo! APIs - Open Hack India 2011

The easiest way to start with YQL is to use the console

http://developer.yahoo.com/yql/console

Page 22: YQL & Yahoo! APIs - Open Hack India 2011

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

Page 23: YQL & Yahoo! APIs - Open Hack India 2011
Page 24: YQL & Yahoo! APIs - Open Hack India 2011
Page 25: YQL & Yahoo! APIs - Open Hack India 2011
Page 26: YQL & Yahoo! APIs - Open Hack India 2011

URL STRUCTURE

http://query.yahooapis.com/v1/yql?[params] http://query.yahooapis.com/v1/public/yql?[params]

Params •  q = [ YQL QUERY ] •  format = [ XML / JSON ] •  diagnostics = [ true / false ] •  debug = [ true / false ] •  callback = [ function name ]

Page 27: YQL & Yahoo! APIs - Open Hack India 2011

LET’S SEE IT

Page 28: YQL & Yahoo! APIs - Open Hack India 2011

QUERY EXAMPLES

Find hackday tweets: SELECT * FROM twitter.search where q='hackday’

Search Yahoo! Answers for resolved questions about cars: select * from answers.search where query="cars" and type="resolved”

Translate tweets into Hindi: select * from google.translate where q in (select text from twitter.search where q="hackday") and target='hi';

Extract important terms from top stories on Yahoo! news: select * from search.termextract where context in (select description from rss where url='http://rss.news.yahoo.com/rss/topstories')

Page 29: YQL & Yahoo! APIs - Open Hack India 2011

QUERY EXAMPLES

Find distance between Bangalore and Mumbai: select * from geo.distance where place1="bangalore" and place2="mumbai”

Get stock quotes for Yahoo!, Apple, Google & Microsoft in one query: select * from yahoo.finance.quotes where symbol in ("YHOO","AAPL","GOOG","MSFT")

Shorten a URL: insert into yahoo.y.ahoo.it (url, keysize) values ('http://www.javarants.com', 5)

Search apartments in criagslist: select * from craigslist.search where location="bangalore" and type="apa" and query="indiranagar”

Page 30: YQL & Yahoo! APIs - Open Hack India 2011

QUERY EXAMPLES

Scrape news from Yahoo! Finance: select * from html where url="http://finance.yahoo.com/q?s=yhoo" and xpath='//div[@id="yfi_headlines"]/div[2]/ul/li/a’

Select, filter data from google spreadsheets: select * from csv where url="https://spreadsheets.google.com/pub?key=0ArYndzim-lbrdF8wc3A5QWl1ZGRpdkxRZk80SU9zUXc&output=csv" and col5 like 'Bangalore%’ ;

Page 31: YQL & Yahoo! APIs - Open Hack India 2011

Let’s find openhackindia photos on flickr

Page 32: YQL & Yahoo! APIs - Open Hack India 2011
Page 33: YQL & Yahoo! APIs - Open Hack India 2011

MAKING REQUESTS: FLICKR URLS

<photo farm="3" id="5708163920"

isfamily="0" isfriend="0" ispublic="1" owner="31832337@N04" secret="0075137487" server="2496" title="San Francisco"/>

Page 34: YQL & Yahoo! APIs - Open Hack India 2011

MAKING REQUESTS: FLICKR URLS

http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg

Photo URL  

http://www.flickr.com/photos/{$owner}/{$id} Photo Page URL  

http://www.flickr.com/photos/{$owner} Photo Owner Profile URL  

Page 35: YQL & Yahoo! APIs - Open Hack India 2011
Page 36: YQL & Yahoo! APIs - Open Hack India 2011

https://github.com/saurabhsahni/Hacks/

Page 37: YQL & Yahoo! APIs - Open Hack India 2011

Finding Recent Photos from flickr

Page 38: YQL & Yahoo! APIs - Open Hack India 2011

Some YQL Hacks

Page 39: YQL & Yahoo! APIs - Open Hack India 2011

ChromYQLip is a chrome extension for page scraping via YQL

Open  Hack  Bangalore  2010  Winner  

Page 40: YQL & Yahoo! APIs - Open Hack India 2011

http://bit.ly/chromeYQL

Page 41: YQL & Yahoo! APIs - Open Hack India 2011

VIDEO CLIP

Page 42: YQL & Yahoo! APIs - Open Hack India 2011

http://www.webmeme.in

Page 43: YQL & Yahoo! APIs - Open Hack India 2011

WEBMEME.IN

Fetch multiple feeds in different formats like atom, RSS and transform them into consistent RSS format Select * from rss where url in (‘http://feeds.feedburner.com/pluggd’, ‘http://quatrainman.blogspot.com/atom.xml’, ‘…’)

Filter news containing “india” from multiple feeds: select * from rss where url in ('http://feeds.feedburner.com/TechCrunch', 'http://www.readwriteweb.com/rss.xml','http://gigaom.com/feed/') and description like '%india%’

Page 44: YQL & Yahoo! APIs - Open Hack India 2011

YQL is open – you can get your data tables in our system

Page 45: YQL & Yahoo! APIs - Open Hack India 2011

All you need to do is write an XML schema and put it on Github.

Page 46: YQL & Yahoo! APIs - Open Hack India 2011

http://github.com/yql/yql-tables

Page 47: YQL & Yahoo! APIs - Open Hack India 2011

Here is the craigslist search table https://github.com/yql/yql-tables/tree/master/craigslist/craigslist.search.xml

Page 48: YQL & Yahoo! APIs - Open Hack India 2011
Page 49: YQL & Yahoo! APIs - Open Hack India 2011

USE INSTANTLY BY UPLOADING ON YOUR SITE

USE 'http://www.mysite.com/my_table.xml' AS mytable; SELECT * FROM mytable WHERE user='saurabh'

Page 50: YQL & Yahoo! APIs - Open Hack India 2011

You can even write server side javascript to build a webservice or augment one. h#p://developer.yahoo.com/yql/guide/yql-­‐execute-­‐chapter.html  

Page 51: YQL & Yahoo! APIs - Open Hack India 2011

There are lot of things you can do with YQL.

Page 52: YQL & Yahoo! APIs - Open Hack India 2011

Play yourself http://developer.yahoo.com/yql/

Page 53: YQL & Yahoo! APIs - Open Hack India 2011

RESOURCES

All Yahoo! APIs and Services http://developer.yahoo.com/everything.html

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

YQL Console http://developer.yahoo.com/yql/console

YQL Github Account (Contribute Tables) http://github.com/yql/yql-tables

Page 54: YQL & Yahoo! APIs - Open Hack India 2011

ANY QUESTIONS?

Saurabh Sahni

Twitter: @saurabhsahni Github: http://github.com/saurabhsahni Web: http://www.saurabhsahni.com

http://www.slideshare.net/saurabhsahni

Page 55: YQL & Yahoo! APIs - Open Hack India 2011
Page 56: YQL & Yahoo! APIs - Open Hack India 2011
Page 57: YQL & Yahoo! APIs - Open Hack India 2011
Page 58: YQL & Yahoo! APIs - Open Hack India 2011
Page 59: YQL & Yahoo! APIs - Open Hack India 2011
Page 60: YQL & Yahoo! APIs - Open Hack India 2011