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
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
JavaScript
| Code sample | Methods |
|---|---|
| Upload | Any method requiring authorization |
| Retrieve current user's uploads |
channels.listplaylistItems.list
|
| Create a playlist | playlists.insert |
| Search for videos related to a keyword | search.list |
.NET
PHP
Python
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.listplaylistItems.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.