YOUTUBE API

Post date: Sep 12, 2016 10:06:15 PM

/**

* This sample finds the active user's uploads, then updates the most recent

* upload's description by appending a string.

*/

function updateVideo() {

// 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 videoID 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');

}

}