Skip to content

Instantly share code, notes, and snippets.

@misterhay
Last active December 11, 2021 17:04
Show Gist options
  • Save misterhay/0e5819a920fd6d93c1daf8df94acdb8b to your computer and use it in GitHub Desktop.
Save misterhay/0e5819a920fd6d93c1daf8df94acdb8b to your computer and use it in GitHub Desktop.
Google Apps Script function to change a YouTube video's privacy status
// 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