YouTube Data API (v3) Code Samples

The lists below identify the code samples available for the YouTube Data API (v3). Full samples can be downloaded from our GitHub projects.

Data API code snippets tool

In addition to the samples listed on this page, the Data API Code Snippets tool provides short code snippets for common YouTube Data API use cases. Code snippets are currently available for all read-only API methods in Apps Script, Go, JavaScript, PHP, Python, and Ruby.

For each method, the tool shows code samples for one or more use cases. For example, it provides five code snippets for the search.list method:

  • List videos by keyword
  • List videos by location
  • List live events
  • Search for the authenticated user's videos
  • List related videos

For each use case, the tool displays the parameters used in the API request. You can modify the parameter values, in which case the tool updates the code snippets to reflect the parameter values that you provided. The tool also displays the API response to each request. If you have modified the request parameters, the API response is based on your provided parameter values.

Standalone code snippets

Apps Script

Code sample Methods
Add a channel subscription subscriptions.insert
Post a channel bulletin activities.insert
Retrieve current user's uploads channels.list
Search for videos related to a keyword search.list
Update a video videos.update

Go

Code sample Methods
Authorize a request Any method requiring authorization.
Post a channel bulletin activities.insert
Retrieve current user's uploads playlistItems.list
Search for videos related to a keyword search.list
Upload a video videos.insert

Java

Code sample Methods
Authorize a request Any method that requires authorization
Add a channel subscription subscriptions.insert
Add a featured video channels.update
Create a playlist playlists.insert
Create and manage caption tracks captions.insert
captions.list
captions.update
captions.download
captions.delete
Create and manage comment threads commentThreads.insert
commentThreads.list
commentThreads.update
Create and manage comments commentThreads.list
comments.insert
comments.list
comments.update
comments.setModerationStatus
comments.markAsSpam
comments.delete
Post a channel bulletin activities.insert
Retrieve my uploads channels.list
playlistItems.list
Search by geolocation search.list
Search by keyword search.list
Set and retrieve localized channel metadata channels.list
channels.update
Set and retrieve localized channel section metadata channelSections.list
channelSections.update
Set and retrieve localized playlist metadata playlists.list
playlists.update
Set and retrieve localized video metadata videos.list
videos.update
Update a video videos.update
Upload a video videos.insert
Upload a video thumbnail image thumbnails.set

JavaScript

Code sample Methods
Upload Any method requiring authorization
Retrieve current user's uploads channels.list
playlistItems.list
Create a playlist playlists.insert
Search for videos related to a keyword search.list

.NET

Code sample Methods
Create a playlist playlists.insert
Retrieve current user's uploaded videos channels.list
playlistItems.list
Search for videos related to a keyword search.list
Upload a video videos.insert

PHP

Code sample Methods
Add a channel section channelSections.insert
Add a channel subscription subscriptions.insert
Create a playlist playlists.insert
Create and manage caption tracks captions.insert
captions.list
captions.update
captions.download
captions.delete
Create and manage comment threads commentThreads.insert
commentThreads.list
commentThreads.update
Create and manage comments commentThreads.list
comments.insert
comments.list
comments.update
comments.setModerationStatus
comments.markAsSpam
comments.delete
Retrieve my uploads channels.list
playlistItems.list
Search by geolocation search.list
Search for videos related to a keyword search.list
Set and retrieve localized channel metadata channels.list
channels.update
Set and retrieve localized channel section metadata channelSections.list
channelSections.update
Set and retrieve localized playlist metadata playlists.list
playlists.update
Set and retrieve localized video metadata videos.list
videos.update
Shuffle existing channel sections channelSections.list
channelSections.update
Update a video videos.update
Upload a banner image and set as channel's banner channelBanners.insert
Upload a custom video thumbnail image thumbnails.set
Upload a video videos.insert

Python

Code sample Methods
Add a chanel section channelSections.insert
Add a channel subscription subscriptions.insert
Set invideoPromotion properties for a channel channels.update
Create a playlist playlists.insert
Create and manage caption tracks captions.insert
captions.list
captions.update
captions.download
captions.delete
Create and manage comment threads commentThreads.insert
commentThreads.list
commentThreads.update
Create and manage comments commentThreads.list
comments.insert
comments.list
comments.update
comments.setModerationStatus
comments.markAsSpam
comments.delete
Like a video videos.rate
Post a channel bulletin activities.insert
Remove a watermark image from a channel watermarks.unset
Retrieve my uploads channels.list
playlistItems.list
Search by geolocation search.list
Search for videos related to a keyword search.list
Set and retrieve localized channel metadata channels.list
channels.update
Set and retrieve localized channel section metadata channelSections.list
channelSections.update
Set and retrieve localized playlist metadata playlists.list
playlists.update
Set and retrieve localized video metadata videos.list
videos.update
Shuffle existing channel sections channelSections.list
channelSections.update
Update a video videos.update
Upload a banner image and set as channel's banner channelBanners.insert
Upload a custom video thumbnail image thumbnails.set
Upload a video videos.insert
Upload a watermark image and set it for a channel watermarks.set

Ruby

Code sample Methods
Authorize a request Any method requiring authorization.
Create a channel subscription subscriptions.insert
Post a channel bulletin activities.insert
Retrieve current user's uploads channels.list
playlistItems.list
Search for videos related to a keyword search.list
Upload a video videos.insert

You may also be able to adapt one of the other Ruby samples.

Send feedback about...

YouTube Data API
YouTube Data API