Google Apps Script function to change a YouTube video's privacy status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// schedule this Google Apps Script function to run at a certain time to change a YouTube video's privacy status | |
function updateVideoPrivacy() { // enable the YouTube Data API under "Services" | |
var channels = YouTube.Channels.list('contentDetails', {mine: true}); | |
for (var i=0; i<channels.items.length; i++) { | |
var uploadsPlaylistId = channels.items[i].contentDetails.relatedPlaylists.uploads; | |
var playlistResponse = YouTube.PlaylistItems.list('snippet', {playlistId: uploadsPlaylistId, maxResults: 1}); // or more than 1 if needed | |
var video = playlistResponse.items[0]; // the first video in the list we retrieved | |
var metadata = { | |
status: {'privacyStatus': 'private'}, // public, unlisted, private | |
id: video.snippet.resourceId.videoId}; // we need to include the video ID from the playlist response | |
YouTube.Videos.update(metadata, 'id,status') // update the video's privacy status | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment