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
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.
Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory