Chat with us, powered by LiveChat

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