Scrape Videos of Any Youtube Channel with Google Sheet

If you are looking for a way to scrape a Youtube Channel videos using your google sheet, then this is the perfect method you need to try. This method involves a google sheet script but don’t worry I will break it down for you how this script works.

Using this script you can now easily scrape all the video URL’s together with their Video Title, and immediately see the result on your google sheet.

PART 1: Create a Youtube V3 API with Google Cloud Console.

  • Go to the Google Cloud Console.
  • Create a new project.
  • On the left side menu click on “APIs & Services > Dashboard”.
  • Find the “ENABLE APIS AND SERVICES”.
  • On the search bar type in “YouTube Data API v3” click and enable it.
  • When its enabled you should see the “Manage” button. Click it.
  • Now, go to “Credentials” and create an API key.
  • Copy the newly generated API key.

PART 2: On Your Google Sheet

  • Go to your google sheet and create ‘New Sheet’
  • On the top menu, click on ‘Extensions’ and click on ‘Apps Script’.
  • Remove any code on the screen and copy our code below.
  • Replace the ‘YOU_API_KEY’ part with your API KEY.
  • Take note, ‘CHANNEL_ID’ should be replaced with the Channel ID you wan to scrape videos from.
function listVideos() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.appendRow(['Title', 'Video ID', 'URL']);  // Headers

  var apiKey = 'YOUR_API_KEY';  // Replace with your YouTube Data API key
  var channelId = 'CHANNEL_ID'; // Replace with the YouTube channel ID
  var pageToken = '';
  var url = '';
  
  do {
    url = 'https://www.googleapis.com/youtube/v3/search?key=' + apiKey + '&channelId=' + channelId + '&part=snippet,id&order=date&maxResults=50' + (pageToken ? '&pageToken=' + pageToken : '');
    var response = UrlFetchApp.fetch(url);
    var json = JSON.parse(response.getContentText());
    
    json.items.forEach(function(item) {
      if(item.id.kind === "youtube#video") {
        sheet.appendRow([item.snippet.title, item.id.videoId, 'https://www.youtube.com/watch?v=' + item.id.videoId]);
      }
    });
    
    pageToken = json.nextPageToken;
  } while (pageToken);
}

PART 3: Finding the Channel ID

Normally, you can easily find the channel ID on the URL itself of the Youtube Channel such as this:

https://www.youtube.com/channel/UC3WmZDwE_jGpzDVxrXdfzrQ

The highlighted part of the URL is the channel ID which is UC3WmZDwE_jGpzDVxrXdfzrQ. This portion is what we need to paste on the ‘CHANNEL_ID’ part of our script.

But, sometimes some channels don’t use this kind of URL, we call this Vanity URL’s like this:

https://www.youtube.com/@MrBeast

Take note that ‘@MrBeast’ is not the channel ID for this URL. If you use this on our script, it will not work!

On this URL, the channel ID is not immediately visible, you need some little trick to find the channel ID for these kind of Channels.

Finding Channel ID from Vanity URL’s

To find the correct channel id from these URL’s here are the steps:

  • Open up your Browser (Chrome) and open up the Channel URL. Right click anywhere and click the View page source.
  • Now, type ‘Ctrl + F’ for the ‘Find’ function and type in ‘channelid’,
  • Copy the series of strings next to it, normally it starts with UCXXXXXX.
  • You may see multiple channelid occurence, copy all of those and run it on our script one by one.

Run the Script

After making sure that you have entered the correct API and the Channel Id you are now ready to run the script. Click on the ‘Save’ and ‘Run’ it afterwards.

Note: When you are running it for the first time, you will be ask to allow permissions, this is a one time process and you will not be asked anymore on succeeding runs.

Result

Video Tutorial

And that’s how you scrape a youtube channel and gather all its video urls using only your google sheet! If you want to check the video URL’s individually, like check how many views, likes, comments, it got you may want to checkout our Mass video details scraper using only guess what your google sheet!

Leave a Comment