Description: The auth.js script demonstrates how to use the Google APIs Client Library for JavaScript
to provide API access and authorize user requests. All of the subsequent samples on this page use this script to
authorize their requests.
For requests that do not require authentication, you could also use the
key query parameter to specify an API key rather than using OAuth 2.0.
Note: You need to update the client ID in the auth.js file. You can obtain your own
client ID by registering your application in the
Google Developers Console.
Description: This code sample demonstrates how to execute a resumable upload using XHR/CORS.
Method: youtube.videos.insert
Description: This JavaScript sample performs the following functions:
- It retrieves the channel name and thumbnail of the authenticated user's channel using the API's channels.list method.
- It handles the video upload to YouTube using the resumable upload protocol.
- It polls for the uploaded video's upload and processing status using the API's videos.list method by setting the part parameter value to status.
The HTML page uses JQuery, the plusone.js and upload_video.js JavaScript files, and the
upload_video.css file to upload a video file to YouTube.
Note that if you use this code in your own application, you must replace the value of the data-clientid attribute in the code for the Sign-In Button
with your project's client ID. The only valid JavaScript origin for the client ID in the sample code is
http://localhost. This means that you could test the sample locally, but it would not work in your
production application.
Method: youtube.playlistItems.list
Description: This code sample calls the API's playlistItems.list method to retrieve a list of
videos uploaded to the channel associated with the request. The code also calls the channels.list
method with the mine parameter set to true to retrieve the playlist ID that identifies
the channel's uploaded videos.
Method: youtube.search.list
Description: This code sample calls the API's search.list method to retrieve search results associated
with a particular keyword.
Method: youtube.playlists.insert
Description: This sample creates a private playlist and add videos to it. (You could, of course, modify the code so
that it creates a publicly visible playlist or so that it checks a form value to determine whether the playlist is
public or private.) Note that you need to update the client ID in the auth.js file to run this code.
Method: youtubeAnalytics.reports.query
Description: This sample uses the YouTube Data and YouTube Analytics APIs to retrieve YouTube channel metrics.
The samples use the Google APIs JavaScript client library
to demonstrate API functionality. The Building a Sample Application
document walks you through the steps of building this application and discusses different portions of this code in more
detail.