YouTube API: Dive In

44
YouTube API: Dive-In HigEdWebDev 2009 Ron West

description

The YouTube API discovery presentation. Defines the API in general terms and outlines the way in which you can interact with YouTube assets.

Transcript of YouTube API: Dive In

Page 1: YouTube API: Dive In

YouTube API: Dive-In

HigEdWebDev 2009Ron West

Page 2: YouTube API: Dive In

Google's mission

• …is to organize the world's information and make it universally accessible and useful. Sometimes making information accessible requires making it available in contexts other than a web browser.

Page 3: YouTube API: Dive In

Agenda

• Introduction• Getting Started• Get Content• Interaction• Pulling it Together• Developer Community

Page 4: YouTube API: Dive In

Introduction

YouTube in ReviewREST

Google Data APIYouTube Data API

Entries/FeedsAuthentication

Page 5: YouTube API: Dive In

YouTube in Review

• Videos• Comments• Ratings• Users• Categories• Keywords/Tags• Channels• Subscriptions

• Messages• Activity Feeds• Recommendations• Friends• Related Videos• Captions• Favorites• Insight Data

Page 6: YouTube API: Dive In

REST

• REpresentational State Transfer• Architectural Style – NOT – Standard• More akin to Doc Literal than RPC based Web

Service• Logical URL’s vs. Static URL’s

Page 7: YouTube API: Dive In

REST

• Client-Server• Stateless• Cacheable• Uniform Interface• Layered

Page 8: YouTube API: Dive In

REST

• HTTP Methods– Get = List or Retrieve– Put = Replace or Update– Post = Create– Delete = Delete

Page 9: YouTube API: Dive In

SOAP (RPC/Doc Literal) Web Services

Pros •Single endpoint for all calls• Lanugage, platform and transport agnostic• Built in error handling

Cons• Conceptually more difficult• Harder to develop with (requires tools)

Page 10: YouTube API: Dive In

Multiple Endpoints

Pros• Language and platform agnostic• Simpler to develop than SOAP• Concise

Cons• Lack of standards• Tied to HTTP transport

REST Web Services

Page 11: YouTube API: Dive In

• Get Video(s)• Edit Video• Delete Video

Get API URL’s for:• Comments• Related Videos• Ratings• Mobile• Versions

Page 12: YouTube API: Dive In

Google Data API

• RSS vs. Atom• APP• Get vs. Post vs. Put vs. Delete

Page 13: YouTube API: Dive In

Response Codes

• Same response codes for HTTP– 200, 201, 301, 400, 500 etc..

• Codes have similar meaning for each type of call– 200 (OK)– 400 (Bad Request)– 401 (Not Authorized)– 404 (Not Found)– 500 (Internal Error)

• Accompanied with error details (XML in payload)

Page 14: YouTube API: Dive In

YouTube Data API

• Version 1• Version 2 (recommended)

Page 15: YouTube API: Dive In

YouTube Data API

• Search for Videos– Keywords (tags)– Categories– Query Params (metadata)

• Search for Playlists– Keywords (tags)– Categories

• Search for Channels– Keywords (tags)– Categories

Page 16: YouTube API: Dive In

YouTube Data API• Retrieve

– Videos– Comments– Captions– Related Videos– Video Responses– Categories– Keywords– Playlists– Subscriptions– Profiles– Contacts– Messages– Activity Feeds– Insight Data Feed– Favorites

Page 17: YouTube API: Dive In

YouTube Data API (cont.)

• Create– Videos– Comments– Captions– Related Videos– Video Responses– Complaint– Rating– Contact– Message– Favorite– Playlist– Subscription

Page 18: YouTube API: Dive In

YouTube Data API (cont.)• Update

– Video Metadata– Captions– Profiles– Playlists– Contacts

• Delete– Video– Message– Favorite– Playlist– Subscription– Contact

Page 19: YouTube API: Dive In

YouTube Data API

• Batch Processing– Process multiple types of calls in a single request– Each Request in its own <entry> tag

Page 20: YouTube API: Dive In

Sample Interaction

• Query API for videos tagged with “SHU”• Display Videos in List• Allow user to Select Video to Display• Display Single Video• Retrieve Comments for that Video• Post Comment• Login• Add to Playlist

Page 21: YouTube API: Dive In

Feed<feed [namespaces]>

… metadata …<openSearch:totalResults /><openSearch:startIndex /><openSearch: itemsPerPage /><entry>

… metadata …<media:group/>

</entry> <entry>

… metadata …<media:group/>

</entry>…

</feed>

Page 22: YouTube API: Dive In

Entry (video)<entry [namespaces]>

<title/><content/>… metadata …<link rel=“http://gdata.youtube.com/schemas/2007#video.responses “/><link rel=“http://gdata.youtube.com/schemas/2007#video.related” /><link rel=“http://gdata.youtube.com/schemas/2007#mobile”/><media:group>

<media:content yt:format=“t” url=“…”/><media:thumbnail url=“…” width=“…” height=“…”/><yt: duration /><yt:videoid />

</ media:group ></entry>

Page 23: YouTube API: Dive In

Authentication

• AuthSub – YouTube Authentication with “callback” API [difficult]

• OAuth – Standardized Approach (similar in nature to OpenID) [most difficult]

• ClientLogin – Custom Authentication – you call YouTube API track token [easiest]

Page 24: YouTube API: Dive In

Getting Started

Google Developers KeyDevelopment Environment

Samples

Page 25: YouTube API: Dive In

Google Developers Key

http://code.google.com/apis/youtube/dashboard/

Page 26: YouTube API: Dive In

Development Environment

• Accessing dev servers• Plugging in Developers Key

Page 27: YouTube API: Dive In

Getting YouTube Content

Standard FeedsDiscovering Videos

ChannelsPlaylists

Displaying Videos

Page 28: YouTube API: Dive In

Standard Feeds

http://code.google.com/apis/youtube/2.0/reference.html#Standard_feeds

• Top Rated• Top Favorites• Most Viewed• Most Popular• Most Recent• Etc…• Filter by Time• Filter by Region• Filter by Category

Page 29: YouTube API: Dive In

Discovering Videos

• Keywords• Categories• Categories/Keywords• Users

Page 30: YouTube API: Dive In

Categorieshttp://gdata.youtube.com/schemas/2007/categories.cat

<app:categories [namespaces]> <atom:category term="Film" label="Film &amp; Animation" xml:lang="en-US"> <yt:assignable/> <yt:browsable regions="AU BR CA CZ DE ES FR GB HK IE IL IN IT JP KR MX NL NZ PL PT RU SE TW US"/> </atom:category></app>

Page 31: YouTube API: Dive In

Video by Keyword/Tag

http://gdata.youtube.com/feeds/api/videos/

• Append /-/keyword/ to video feed URL• Use query string ?category=keyword• Not (-) Or (|)– /-/Kennedy/-Bobby/-Ted/-Patrick– /-/Kennedy/Bobby|Ted|Patrick

Page 32: YouTube API: Dive In

Video by Category

http://gdata.youtube.com/feeds/api/videos/

• Append /-/Category/ to video feed URL• Use query string ?category=Category• Multiple Categories– /-/Comedy/Music/Shortmov/– ?category=Comedy,Music,Shortmov

• Category ARE case sensitive

Page 33: YouTube API: Dive In

Channelshttp://gdata.youtube.com/feeds/api/channels?v=2

• Search just like videos using “?q=keywords/tags”

<feed [namespaces>… metadata …<openSearch:totalResults /><openSearch:startIndex /><openSearch: itemsPerPage /><entry>

<title /><summary /><gd:feedlink url=“…” hitcount=“…”>

</entry></feed>

Page 34: YouTube API: Dive In

Playlists

http://gdata.youtube.com/feeds/api/playlists/snippets?v=2

• Searchjust like a Channel<feed [namespaces>

… metadata …<openSearch:totalResults /><openSearch:startIndex /><openSearch: itemsPerPage /><entry>

<title /><summary /><content src=“…”><yt:countHint /><yt:playlistId />

</entry></feed>

Page 35: YouTube API: Dive In

Displaying Videos

• JavaScript API• Flash API

Page 36: YouTube API: Dive In

Interacting with YouTube Content

AuthenticationComments

RatingsUpdatingUploading

Page 37: YouTube API: Dive In

ClientLogin

https://www.google.com/youtube/accounts/ClientLogin

• Pass in:– Email– Passwd

• Receive: Auth=AIwbFARksypDdUSGGYRI_5v7Z9TaijoPQqpIfCEjTFPAikn_---OC-I1VJtQ

YouTubeUser=testuser• Send into all requests:

Header:Authorization = “GoogleLogin auth=

AIwbFARksypDdUSGGYRI_5v7Z9TaijoPQqpIfCEjTFPAikn_---OC-I1VJtQ”

Page 38: YouTube API: Dive In

Comments

• Get Video Feed• Look for:

<gd:comments><gd:feedlink href=“…” countHint=“…” />

</gd:comments>• Pass in

Page 39: YouTube API: Dive In

Ratings

• Link embeded in the video feed<link

rel='http://gdata.youtube.com/schemas/2007#video.ratings' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/VIDEO_ID/ratings'/>

• Send back to this URL:<entry [namespaces]>

<gd:rating value="4" min="1" max="5"/></entry>

Page 40: YouTube API: Dive In

Updating• Link embeded in the video feed<link rel='edit' type='application/atom+xml'

href='http://gdata.youtube.com/feeds/api/users/andyland74/uploads/914IMX9RSTE'>

• Send Back to this URL:<entry [namespaces]>

<media:group><media:title type=“…“ /><media:description type=“…“ /><media:category scheme=“…“ /><media:keywords />

</media:group> </entry>

Page 41: YouTube API: Dive In

Uploading

http://uploads.gdata.youtube.com/feeds/api/users

• Include in Header– Authentication– Slug (filename)

• Include in Body– Video File<entry [namespace]>

<media:group> <media:title type=”...” />

<media:description type=“…“ /><media:keywords /><media:category scheme=“…“ />

</media:group></entry>

Page 42: YouTube API: Dive In

Challenges

• Documentation is poor• No true congruity in related links• Error messages are non-descriptive

Page 43: YouTube API: Dive In

Developer Resources

• Google Group– http://groups.google.com/group/youtube-api-

gdata• Google Code Help– http://code.google.com/support/bin/topic.py?

topic=12357

Page 44: YouTube API: Dive In

Contact

• Ron West• @notronwest• facebook.com/notronwest• www.notronwest.com/blog