Create YouTube Playlist with Google Script and Sheets

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);
  }
}

Amit Agarwal is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

Want to stay up to date?
Sign up for our email newsletter.

We will never send any spam emails. Promise 🫶🏻