You are on page 1of 31

Youtube API

Mohammed Abdallah

Session Overview
Youtube (platform) Youtube API Examples

This presentation was made specially For this GTUG Event @2012

Youtube platform
Linux (suse) Apache Mysql Python Lighttpd

This presentation was made specially For this GTUG Event @2012

Video ID
Base 64
A-Z, a-z, 0-9, +, or / Padding 0, 1, 2 with = at the end Ex: eW91dHViZQ==

Youtube Video Id (modified base64)


A-Z, a-z, 0-9, _, or No padding with = Ex: YWt4wmZ_EMI
This presentation was made specially For this GTUG Event @2012

Youtube API
Player API
Front-end Javascript, ActionScript 3 Embedded, Chromeless

Youtube Data API


Server-side XML and HTTP Uploading
This presentation was made specially For this GTUG Event @2012

Player API
Embedded
AS2 (deprecated) AS3

Chromeless
Javascript ActionScript 3 No controls (HTML controls)
This presentation was made specially For this GTUG Event @2012

Player API (Parameters)


autohide autoplay color controls enablejsapi fs hd loop showinfo showsearch theme
This presentation was made specially For this GTUG Event @2012

Player API (Embedded)


http://www.youtube.com/v/VIDEO_ID
<object width="425" height="355"> <param name="movie" value="http://www.youtube.com/v/VIDEO_ID? version=3&autohide=1&showinfo=0"></param> <param name="allowScriptAccess" value="always"></param> <embed src="http://www.youtube.com/v/VIDEO_ID? version=3&autohide=1&showinfo=0" type="application/x-shockwave-flash" allowscriptaccess="always" width="425" height="355"></embed> </object>
This presentation was made specially For this GTUG Event @2012

Player API (Chromeless)


Javascript API: load a video
<div id="ytplayer"></div> <script type="text/javascript"> var params = { allowScriptAccess: "always" }; swfobject.embedSWF( "http://www.youtube.com/v/VIDEO_ID? enablejsapi=1&playerapiid=ytplayer", "ytplayer", "425", "365", "8", null, null, params); </script>
This presentation was made specially For this GTUG Event @2012

Player API (Chromeless)


<script type="text/javascript">

function play() { if (ytplayer) { ytplayer.playVideo(); } } </script>


<a href="javascript:void(0);" onclick="play();">Play</a>

This presentation was made specially For this GTUG Event @2012

Youtube Data API


Searching Retrieving Uploading Updating Deleting Community No downloading
This presentation was made specially For this GTUG Event @2012

API Version
2 User has Youtube Account 2.1 User has not Youtube Account (using Google account) 1 Not valid request v parameter
This presentation was made specially For this GTUG Event @2012

Client Libraries
Java .NET PHP Python Objective-C

This presentation was made specially For this GTUG Event @2012

Feed Types
Video feed User's Playlists feed Video comments feed User's profile feed User's contacts feed User's subscriptions feed

This presentation was made specially For this GTUG Event @2012

Video feed
Videos feed Standard feeds Playlist feed

This presentation was made specially For this GTUG Event @2012

API Query Parameters


alt: atom, rss, json, json-in-script, and jsonc max-results start-index v

This presentation was made specially For this GTUG Event @2012

Searching

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

http://gdata.youtube.com/feeds/api/videos? q=Gaza &start-index=21 &max-results=10 &v=2

This presentation was made specially For this GTUG Event @2012

Searching parameters
duration:
short: less than 4 minutes medium: between 4 and 20 minutes long: longer than 20 minutes

Format:
1: RTSP streaming URL for mobile video playback. H.263 video 5: HTTP URL to the embeddable 6: RTSP streaming URL for mobile video playback. MPEG-4 SP video
This presentation was made specially For this GTUG Event @2012

Searching parameters
hd orderby:
relevance published viewCount rating

This presentation was made specially For this GTUG Event @2012

Searching (Example)
$yt = new Zend_Gdata_YouTube(); $query = $yt->newVideoQuery(); $query->setQuery($searchTerm); $query->setStartIndex($startIndex); $query->setMaxResults($maxResults); $feed = $yt->getVideoFeed($query);

This presentation was made specially For this GTUG Event @2012

Searching (Example)
foreach ($feed as $entry) { $videoId = $entry->getVideoId(); $thumbnailUrl = $entry->mediaGroup->thumbnail[0]->url; $videoTitle = $entry->mediaGroup->title; $videoDescription = $entry->mediaGroup->description; // print result }

This presentation was made specially For this GTUG Event @2012

Uploading
Browser-based uploading Direct upload

This presentation was made specially For this GTUG Event @2012

Authentication
AuthSub ClientLogin OAuth

This presentation was made specially For this GTUG Event @2012

Browser-based uploading
Upload video metadata API response (URL, Token) Upload the video file

This presentation was made specially For this GTUG Event @2012

Browser-based uploading
POST: gdata.youtube.com/action/GetUploadToken

authentication_token ClientLogin, AuthSub single-use, AuthSub session, OAuth developer_key content_length API_XML_Request
This presentation was made specially For this GTUG Event @2012

API_XML_REQUEST
<?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">Youtube API GTUG Gaza</media:title> <media:description type="plain"> Youtube API session </media:description> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People </media:category> <media:keywords>youtube, api</media:keywords> </media:group> </entry>
This presentation was made specially For this GTUG Event @2012

Soft cap!
Youtube accounts have soft cap of 2000 videos.
After first 2000, 50 additional videos/day

This presentation was made specially For this GTUG Event @2012

Direct Upload
POST: uploads.gdata.youtube.com/feeds/api/users/default/uploads

youtube_username (ClientLogin only) authentication_token developer_key video_filename boundary_string content_length API_XML_Request video_content_type Binary File Data (such as video/mp4 or application/octet-stream)
This presentation was made specially For this GTUG Event @2012

Links
Dashboard: https://code.google.com/apis/youtube/dashboard/gwt/ Create Channel: http://www.youtube.com/create_channel

This presentation was made specially For this GTUG Event @2012

https://developers.google.com/youtube/2.0/devel opers_guide_php

This presentation was made specially For this GTUG Event @2012

Thank you

This presentation was made specially For this GTUG Event @2012

You might also like