Create YouTube Playlist with Google Script and Sheets

C
Published in: Google Apps Script - YouTube

This Google Scripts reads the list of YouTube Video IDs from a Google Spreadsheet and adds them all to an existing playlist in YouTube.

Please enable the YouTube API under Advanced Google Services and inside the corresponding Google Cloud Platform project. You can also create YouTube playlist by appending the video IDs to a special URL.

function addVideoToYouTubePlaylist() {
  // Read the source videos from Google Sheet
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();

  // Add your own playlist Id here
  var playlistId = "PLAYLIST_ID_HERE";

  // iterate through all rows in the sheet
  for (var d=1,l=data.length; d<l; d++) {

    // Add the video the existing playlist
    YouTube.PlaylistItems.insert({
      snippet: {
        playlistId: playlistId,
        resourceId: {
          kind: "youtube#video",
          videoId: data[d][0]
        }
      }
    }, "snippet");

    // wait for a second to avoid hitting the rate limit
    Utilities.sleep(1000);
  }
}
Published in: Google Apps Script - YouTube

Looking for something? Find here!

Meet the Author

Web Geek, Tech Columnist
A
Amit Agarwal

Amit Agarwal is a Google Developer Expert in GSuite and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. Read more on Lifehacker and YourStory

Get in touch