Home > Enterprise >  How to insert a YouTube channel banner using Google Apps Script?
How to insert a YouTube channel banner using Google Apps Script?

Time:05-27

Hello stackoverflow community.

I want to know how to update my channels banner image with the ChannelBanners: insert method from the YouTube Data API on Google Apps Script (https://developers.google.com/youtube/v3/docs/channelBanners/insert)

Can anybody help me to create an Apps Script code to do this?

Thanks for your help!

CodePudding user response:

I believe your goal is as follows.

  • You want to insert a banner to your YouTube channel using Google Apps Script.

In this case, how about the following sample script?

Please put an image file you want to use to your Google Drive, and retrieve the file ID.

Sample script:

Before you use this script, please enable YouTube Data API at Advanced Google services. And, please set your channel ID and the file ID of the image file on your Google Drive.

function myFunction() {
  const channelId = "###"; // Please set your channel ID.
  const fileId = "###"; // Please set the file ID of the image file on Google Drive.

  const blob = DriveApp.getFileById(fileId).getBlob();
  YouTube.ChannelBanners.insert(null, blob, { channelId });
}
  • When this script is run, the retrieved image is set as the banner of the channel.

  • About the image size, the official document says as follows. Please be careful about this.

    Call the channelBanners.insert method to upload the binary image data to YouTube. The image must have a 16:9 aspect ratio and be at least 2048x1152 pixels. We recommend uploading a 2560px by 1440px image.

Reference:

  • Related