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.

Apps Script

  1. Post channel bulletin (activities.insert)
  2. Retrieve my uploads (channels.list)
  3. Search by keyword (search.list)
  4. Search by topic (search.list)
  5. Subscribe to channel (subscriptions.insert)
  6. Update video (videos.update)

Go

  1. Authorize a request
  2. Post a channel bulletin (activities.insert)
  3. Retrieve my uploads (playlistItems.list)
  4. Search by keyword (search.list)
  5. Search by topic (search.list)
  6. Upload a video (videos.insert)

Java

  1. Post a channel bulletin (activities.insert)
  2. Add a featured video (channels.update)
  3. Set and retrieve localized channel metadata (channels.list and channels.update)
  4. Set and retrieve localized channel section metadata (channelSections.list and channelSections.update)
  5. Retrieve my uploads (playlistItems.list)
  6. Create a playlist (playlists.insert)
  7. Set and retrieve localized playlist metadata (playlists.list and playlists.update)
  8. Search by keyword (search.list)
  9. Search by topic (search.list)
  10. Add a channel subscription (subscriptions.insert)
  11. Upload a video thumbnail image (thumbnails.set)
  12. Upload a video (videos.insert)
  13. Update a video (videos.update)
  14. Set and retrieve localized video metadata (videos.list and videos.update)

JavaScript

  1. Authorizing requests
  2. My uploaded videos (playlistItems.list)
  3. Create a playlist (playlists.insert)
  4. Search by keyword (search.list)

.NET

  1. Retrieve my uploads (playlistItems.list)
  2. Create a playlist (playlists.insert)
  3. Search by keyword (search.list)
  4. Upload a video (videos.insert)

PHP

  1. Set and retrieve localized channel metadata (channels.list and channels.update)
  2. Set and retrieve localized channel section metadata (channelSections.list and channelSections.update)
  3. Retrieve my uploads (playlistItems.list)
  4. Create a playlist (playlists.insert)
  5. Set and retrieve localized playlist metadata (playlists.list and playlists.update)
  6. Search by keyword (search.list)
  7. Add a channel subscription (subscriptions.insert)
  8. Uploading a custom thumbnail for a Video (thumbnails.set)
  9. Resumable Uploads (videos.insert)
  10. Updating a Video by adding new tags (videos.list and videos.update)
  11. Set and retrieve localized video metadata (videos.list and videos.update)

Python

  1. Post a channel bulletin (activities.insert)
  2. Upload a banner image and set as channel's banner (channelBanners.insert and channels.update)
  3. Add a featured video (channels.update)
  4. Set and retrieve localized channel metadata (channels.list and channels.update)
  5. Set and retrieve localized channel section metadata (channelSections.list and channelSections.update)
  6. Retrieve my uploads (playlistItems.list)
  7. Create a playlist (playlists.insert)
  8. Set and retrieve localized playlist metadata (playlists.list and playlists.update)
  9. Search by keyword (search.list)
  10. Search by topic (search.list)
  11. Add a channel subscription (subscriptions.insert)
  12. Upload a video thumbnail image (thumbnails.set)
  13. Upload a video (videos.insert)
  14. Rate (like) a video (videos.rate)
  15. Update a video (videos.update)
  16. Set and retrieve localized video metadata (videos.list and videos.update)

Ruby

  1. Authorize a request
  2. Post a channel bulletin (activities.insert)
  3. Retrieve my uploads (playlistItems.list)
  4. Search by keyword (search.list)
  5. Add a channel subscription (subscriptions.insert)
  6. Upload a video (videos.insert)