Date post: | 30-May-2018 |
Category: |
Documents |
Upload: | best-tech-videos |
View: | 215 times |
Download: | 0 times |
of 57
8/14/2019 Overview of the YouTube APIs
1/57
Overview of YouTube APIsAsk not what our APIs can do for you
John Harding
July 10, 2008
8/14/2019 Overview of the YouTube APIs
2/57
YouTube Confidential and Proprietary
The Big Idea
All the functionality of YouTube, available on your web site
Watch Videos
Find relevant videos
Manage favorites, playlists, subscriptions, etc.
Upload
8/14/2019 Overview of the YouTube APIs
3/57
YouTube Confidential and Proprietary
Agenda
Google Data API review
YouTube API basics
Overview of YouTube API functionality
Read
Write
Upload
8/14/2019 Overview of the YouTube APIs
4/57
YouTube Confidential and Proprietary
Google Data API Review
Based on Atom Publishing Protocol (APP)
RESTful design
Data represented as Atom, RSS feeds or JSON
Uses standard HTTP
POST to create resources
GET to retrieve resources
PUT to update resources
DELETE to delete resources
8/14/2019 Overview of the YouTube APIs
5/57
YouTube Confidential and Proprietary
YouTube API basics
Different types of feeds (based on content):
Videos
User subscriptions
User playlists
User contacts
Comments
User profile
Most can be read by anyoneSome information may be private
Modifying always requires authentication
8/14/2019 Overview of the YouTube APIs
6/57
YouTube Confidential and Proprietary
Video Feeds
Video feeds represent a set of videos
Search results
Standard feeds
Related videos
User favorites
User uploads
Playlist contents
Video responses
8/14/2019 Overview of the YouTube APIs
7/57
YouTube Confidential and Proprietary
Video Feeds (Atom)
http://gdata.youtube.com//standardfeeds/most_viewed
8/14/2019 Overview of the YouTube APIs
8/57
YouTube Confidential and Proprietary
Video Feeds (Python Client Library)
yt = gdata.youtube.service.YouTubeService()feed = yt.GetYouTubeVideoFeed(uri)
8/14/2019 Overview of the YouTube APIs
9/57
YouTube Confidential and Proprietary
Video Feeds (English)
A sequence of Video entries, each with:
Title, Description, Author
Category, Keywords
Links to other pages & feeds (Related, Responses, Comments,etc.)
Thumbnails
Statistics (Ratings, View counts, etc.)
Video players (YouTube watch page, Embedded Player)
8/14/2019 Overview of the YouTube APIs
10/57
8/14/2019 Overview of the YouTube APIs
11/57
YouTube Confidential and Proprietary
Search
/feeds/api/videos/?vq=&
Useful Query Parameters (valid on most feeds):
vq: Search Terms
orderby: relevance, published, viewCount, rating
relevance_lang_xx for language-specific relevance
lr: Language restriction
format=5: Only return embeddable videos
Examples:
http://gdata.youtube.com/feeds/api/videos/?vq=lolcatshttp://gdata.youtube.com/feeds/api/videos/?vq=skateboarding&orderby=ratinghttp://gdata.youtube.com/feeds/api/videos/?vq=music+videos&format=5
8/14/2019 Overview of the YouTube APIs
12/57
YouTube Confidential and Proprietary
Standard Feeds
8/14/2019 Overview of the YouTube APIs
13/57
YouTube Confidential and Proprietary
Standard Feeds
/feeds/api/standardfeeds/
Different lists of featured and popular content
Analagous to Videos tab on www.youtube.com:
Featured, Most Viewed, Top Rated, etc.
Some offer a variety of time windows (e.g. time=this_week)
All vary by region
Some are broken down by category (e.g. category=Sports)
http://gdata.youtube.com/feeds/api/standardfeeds/recently_featuredhttp://gdata.youtube.com/feeds/api/standardfeeds/ES/most_viewedhttp://gdata.youtube.com/feeds/api/standardfeeds/FR/top_rated?time=todayhttp://gdata.youtube.com/feeds/api/standardfeeds/top_rated?category=Sports
http://www.youtube.com/8/14/2019 Overview of the YouTube APIs
14/57
YouTube Confidential and Proprietary
Related Videos
8/14/2019 Overview of the YouTube APIs
15/57
8/14/2019 Overview of the YouTube APIs
16/57
YouTube Confidential and Proprietary
Example Time Standard Feeds and Search
8/14/2019 Overview of the YouTube APIs
17/57
YouTube Confidential and Proprietary
Example Time Standard Feeds and Search
[util.py]
def MakeGetRequest(self, path, authsub_token=None):request_headers = {}if authsub_token:request_headers.update({'Authorization':_AuthSubAuthHeader % authsub_token})request_headers.update(self._GetDeveloperHeaders())return Fetch(_GDataHost, 'GET', path, request_headers, None)
def _BuildVideoList(dom):video_entries = dom.getElementsByTagName("entry")videos_list = []for video in video_entries:v = ytvideo.ytvideo()v.parse_from_xml(video)videos_list.append(v)return videos_list
8/14/2019 Overview of the YouTube APIs
18/57
YouTube Confidential and Proprietary
Example Time Standard Feeds and Search
[home.py]
display_videos = GetStandardFeed(server.MOST_VIEWED,count=1, time='this_week')display_videos.extend(GetStandardFeed(server.TOP_RATED,count=1, time='this_week'))display_videos.extend(GetStandardFeed(server.FEATURED,count=1, time=None)
for video in display_videos:response.write(video_display.video_to_html(video))
_GDataStandardFeedsBasePath = '/feeds/api/standardfeeds'def GetStandardFeed(self, feed, time='today', count=5):
path = _GDataStandardFeedsBasePath + '/' + feedif not time is None:path = path + '?time=' + timedom = MakeGetRequest(path)return BuildVideoList(dom)
8/14/2019 Overview of the YouTube APIs
19/57
YouTube Confidential and Proprietary
Example Time Standard Feeds and Search
[search.py]
query = self.request.get('q')if query is None:query = 'YouTube APIs'videos = GetSearchResults(query, category=None)response.write(video_display.video_list_to_html(videos))
_GDataVideoSearchPath = '/feeds/api/videosdef GetSearchResults(self, query, category=None):path = _GDataVideoSearchPathif not category is None:path = path + '/-/' + urllib.quote(category, safe='')
path = path + '?vq=%s' % urllib.quote(query)dom = MakeGetRequest(path)return _BuildVideoList(dom)
8/14/2019 Overview of the YouTube APIs
20/57
YouTube Confidential and Proprietary
Personalization is key
Different ways to personalize the YouTube experience:
Subscriptions
Playlists
Favorites
My uploads
Contacts
8/14/2019 Overview of the YouTube APIs
21/57
YouTube Confidential and Proprietary
Subscriptions
8/14/2019 Overview of the YouTube APIs
22/57
YouTube Confidential and Proprietary
Subscriptions
/feeds/api/users//subscriptions
There are multiple types of subscriptions:
Channel
Favorites
Search query
Differentiate by category
Identify target by entry contents
for Channel, Favorites
for Search
8/14/2019 Overview of the YouTube APIs
23/57
YouTube Confidential and Proprietary
Subscriptions (Atom)
http:///users/mortms/subscriptions/ac3a969d054c3f98virginia tech
8/14/2019 Overview of the YouTube APIs
24/57
8/14/2019 Overview of the YouTube APIs
25/57
YouTube Confidential and Proprietary
Playlists
April 26 2008 at Squaw Valley
A few videos from snowboarding at SquawValley on April 26, 2008
/feeds/api/users//playlists
Each playlist has:
Title
Description
Tags
pointing to playlist contents
8/14/2019 Overview of the YouTube APIs
26/57
YouTube Confidential and Proprietary
Playlist Contents
Android Demo ...1A first hand look at building an Android
application 2
/feeds/api/playlists/
Almost identical to search results, standard feeds, etc.
Playlist contents have
8/14/2019 Overview of the YouTube APIs
27/57
YouTube Confidential and Proprietary
Favorites and User Uploads
8/14/2019 Overview of the YouTube APIs
28/57
8/14/2019 Overview of the YouTube APIs
29/57
YouTube Confidential and Proprietary
Example Time Favorites and User Uploads
8/14/2019 Overview of the YouTube APIs
30/57
YouTube Confidential and Proprietary
Example Time Favorites and User Uploads
feed = yt.GetUserFavoritesFeed(username=danielbeast')
uri = '/feeds/api/users/default/uploads'feed = yt.GetYouTubeVideoFeed(uri)
8/14/2019 Overview of the YouTube APIs
31/57
YouTube Confidential and Proprietary
A note about projections
Projections allow you to get just the data youre interested in
/feeds/api/
All relevant data, using plain text instead of HTML
/feeds/base/Simple responses with HTML for display
/feeds/mobile/
Most compact responses for low-bandwidth mobile devices.
8/14/2019 Overview of the YouTube APIs
32/57
YouTube Confidential and Proprietary
Why should users log in?
Access to restricted information
Private videos
Private playlists
Inbox (video sharing)
Status of videos being processed
Required for all write operations
Modify favorites, playlists, subscriptions
Rate, comment, respond to videosUpload and manage videos
8/14/2019 Overview of the YouTube APIs
33/57
YouTube Confidential and Proprietary
Login
Two ways to sign in
Web applications use AuthSub
Users log in on a Google web page
Browser gets redirected back to your site with authentication token
Installed applications use ClientLogin
Users enter credentials in your application
Your application makes a login request
Your application gets issued a temporary authentication token
8/14/2019 Overview of the YouTube APIs
34/57
YouTube Confidential and Proprietary
AuthSub Overview
Send user to AuthSub login page
https://www.google.com/accounts/AuthSubRequest?
next=http://your.app.com/login_complete
scope=http://gdata.youtube.com
session=1&secure=0
8/14/2019 Overview of the YouTube APIs
35/57
YouTube Confidential and Proprietary
AuthSub Overview
User will be sent back to your site with a one-time use token
http://your.app.com/login_complete?token=
Use or convert to session token
https://www.google.com/accounts/AuthSubSessionToken
Add Authorization header to all requests:
Authorization: AuthSub token=
8/14/2019 Overview of the YouTube APIs
36/57
YouTube Confidential and Proprietary
Basic write operations
Can create, update, and delete data
All write operations require a user auth token
We also require you to register your application
http://code.google.com/apis/youtube/dashboard/
Use one developer key for each application/product
Send auth token, developer key, client id with every request
Authorization: AuthSub token=
X-GData-Key: key=
X-GData-Client:
8/14/2019 Overview of the YouTube APIs
37/57
YouTube Confidential and Proprietary
Basic write operations
Make POST requests to create a new entry:
Favorite
Playlist or playlist item
Subscription
Comments & ResponsesContacts
Some feeds are write-only
RatingsComplaints
8/14/2019 Overview of the YouTube APIs
38/57
YouTube Confidential and Proprietary
Write example
POST /feeds/api/users/default/favorites HTTP/1.1
X-GData-Key: key=X-GData-Client: key=
Authorization: AuthSub token=
Content-Type: application/atom+xml
http://gdata.youtube.com/feeds/videos/u1zgFlCw8Aw
8/14/2019 Overview of the YouTube APIs
39/57
YouTube Confidential and Proprietary
Upload
Two models for upload
Direct Upload
For installed applications
For web apps, if you have (or want) a copy of the video
Browser Upload
For web apps only
Your app controls the metadata
User uploads the video directly to YouTube
8/14/2019 Overview of the YouTube APIs
40/57
YouTube Confidential and Proprietary
Upload
Developer tags allow you to track your uploads
Accessible only with your developer key
Can define your own taxonomy
...my_user_id=john
8/14/2019 Overview of the YouTube APIs
41/57
YouTube Confidential and Proprietary
Direct Upload Example
All uploads go to http://uploads.gdata.youtube.com
POST /feeds/api/users/default/uploads HTTP/1.1
X-GData-Key: key=
X-GData-Client: key=
Authorization: AuthSub token=
Content-Type: multipart/related; boundary=Arbitrary-String
Slug: original_file.mp4
--Arbitrary-String
Content-Type: application/atom+xml
--Arbitrary-String
Content-Type: video/mp4Content-Transfer-Encoding: binary
[Binary data of file]--Arbitrary-String--
8/14/2019 Overview of the YouTube APIs
42/57
8/14/2019 Overview of the YouTube APIs
43/57
YouTube Confidential and Proprietary
Browser Upload Flow
8/14/2019 Overview of the YouTube APIs
44/57
YouTube Confidential and Proprietary
Browser Upload Flow
8/14/2019 Overview of the YouTube APIs
45/57
YouTube Confidential and Proprietary
Browser Upload Flow
8/14/2019 Overview of the YouTube APIs
46/57
YouTube Confidential and Proprietary
Example Time Browser Upload
8/14/2019 Overview of the YouTube APIs
47/57
YouTube Confidential and Proprietary
Browser Upload Example
POST /actions/GetUploadToken HTTP/1.1
X-GData-Key: key=
X-GData-Client: key=
Authorization: AuthSub token=
Content-Type: application/atom+xml; charset=UTF-8
my_user_id=john
http://uploads.gdata.youtube.com/action/FormDataUpload/AIw
AIwbFASb9gtLCYjoE-
Step 3: POST Metadata, including developer tags
Step 4: Receive upload URL and token
8/14/2019 Overview of the YouTube APIs
48/57
YouTube Confidential and Proprietary
Browser Upload Example
Video File:
http://mysite.com/upload_complete?status=200&id=GTdQIBGlEmg
Step 5: Display upload form
Step 8: User gets redirected to your site on completion
8/14/2019 Overview of the YouTube APIs
49/57
YouTube Confidential and Proprietary
Checking Video Status
Not public, so will not show up in public feeds
Retrieve from authenticated user uploads feed:
GET /feeds/api/users/default/uploads/GTdQIBGlEmg HTTP/1.1
X-GData-Key: key=
X-GData-Client: key=
Authorization: AuthSub token=
Check for status tags (not present means video is live):
yes
Also check when showing all of users uploads
8/14/2019 Overview of the YouTube APIs
50/57
YouTube Confidential and Proprietary
Searching with developer tags
Developer tags are simply a category scheme
Search with standard category syntax
{category_scheme}category_name
GET /feeds/api/videos/-/
{/schemas/2007/developertags.cat}my_user_id=john HTTP/1.1
X-GData-Key: key=
X-GData-Client: key=
8/14/2019 Overview of the YouTube APIs
51/57
YouTube Confidential and Proprietary
Example Time Developer Tags
8/14/2019 Overview of the YouTube APIs
52/57
YouTube Confidential and Proprietary
References
Google Data API documentation
http://code.google.com/apis/gdata/overview.html
YouTube Data API documentation
http://code.google.com/apis/youtube/overview.html
YouTube API Developer Forum
http://groups.google.com/group/youtube-api?lnk=srg
8/14/2019 Overview of the YouTube APIs
53/57
Q & A
8/14/2019 Overview of the YouTube APIs
54/57
8/14/2019 Overview of the YouTube APIs
55/57
8/14/2019 Overview of the YouTube APIs
56/57
YouTube Confidential and Proprietary
Video Feeds
Sample video entry
http:///feeds/api/videos/dMH0bHeiRNg
8/14/2019 Overview of the YouTube APIs
57/57
YouTube Confidential and Proprietary
Video Feeds
Sample video entry (contd)
...