Page Summary
-
Google Apps Script can be used to update video details on a YouTube channel, such as the description.
-
A channel bulletin can be posted using Google Apps Script, allowing for communication with subscribers.
-
All video uploads for a channel can be retrieved and listed using Google Apps Script.
-
Videos can be searched on YouTube by keyword or Freebase topic using Google Apps Script.
-
Users can subscribe to a specific YouTube channel programmatically through Google Apps Script.
Update video's details
function updateYouTubeVideo() { // 1. Fetch all the channels owned by active user. var myChannels = YouTube.Channels.list('contentDetails', {mine: true}); // 2. Iterate through the channels and get the uploads playlist ID. for (var i = 0; i < myChannels.items.length; i++) { var item = myChannels.items[i]; var uploadsPlaylistId = item.contentDetails.relatedPlaylists.uploads; var playlistResponse = YouTube.PlaylistItems.list('snippet', { playlistId: uploadsPlaylistId, maxResults: 1 }); // Get the ID of the first video in the list. var video = playlistResponse.items[0]; var originalDescription = video.snippet.description; var updatedDescription = originalDescription + ' Description updated via Google Apps Script'; video.snippet.description = updatedDescription; var resource = { snippet: { title: video.snippet.title, description: updatedDescription, categoryId: '22' }, id: video.snippet.resourceId.videoId }; YouTube.Videos.update(resource, 'id,snippet'); console.log('Video with ID = %s and Title = %s was successfully updated.', video.snippet.resourceId.videoId, video.snippet.title); } }
Create a channel bulletin
function postChannelBulletin() { var message = 'Thanks for subscribing to my channel! This posting is ' + 'from Google Apps Script'; var videoId = 'INSERT_VIDEO_ID_HERE'; var resource = { snippet: { description: message }, contentDetails: { bulletin: { resourceId: { kind: 'youtube#video', videoId: videoId } } } }; var response = YouTube.Activities.insert(resource, 'snippet,contentDetails'); console.log('Posted to channel bulletin successfully.'); }
Retrieve video uploads
function retrieveVideoUploads() { var results = YouTube.Channels.list('contentDetails', {mine: true}); for (var i in results.items) { var item = results.items[i]; // Get the playlist ID, which is nested in contentDetails, as described in // the Channel resource: // https://developers.google.com/youtube/v3/docs/channels var playlistId = item.contentDetails.relatedPlaylists.uploads; var nextPageToken = ''; // This loop retrieves a set of playlist items and checks the nextPageToken // in the response to determine whether the list contains additional items. //