Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the subscriber count of a YouTube channel to Google Sheets

I have a list of YouTube channels' URLs. How do I get their subscriber count to a Google Sheet?

like image 700
mert dökümcü Avatar asked Oct 25 '25 06:10

mert dökümcü


1 Answers

YouTube Data API v3 credentials will be required. See:

  • YouTube Data API Overview
  • Obtaining Credentials

Once you get the API key:

  1. Get your URL list to a Google Sheet.

  2. Create a new Google Apps Script project. (Tools > Script Editor)

  3. Paste this code to your script file:

     var api_key='YOUR_API_KEY'
     var google_url = 'https://www.googleapis.com/youtube/v3/channels/' 
     var url_id = google_url + '?key=' + api_key + '&part=statistics' + '&id='
    
     function GET_SUBS(input) {
         /** Takes channel ID as input and returns the subscriber count */
         url_id = url_id + input
         return +ImportJSON(url_id, "/items/statistics/subscriberCount", "noHeaders")
     }
    
  4. Click on the plus icon next to the "Files" and choose "Script". Rename your new script file as "ImportJSON" and paste this code.

  5. Go back to the sheet and set up a column for channel IDs. You can use the following code to strip ID of a channel from the URL:

    =ArrayFormula(REGEXREPLACE('CHANNEL_URL',"(.*\/)(.*)$","$2"))
    

Sample table.

  1. Use the GET_SUBS() function to get the follower count.

    GET_SUBS('CHANNEL_ID')
    

Note: Currently YouTube API doesn't provide the exact subscriber count of a channel publicly. See this Stackoverflow question. So the results we have are rounded.

like image 95
mert dökümcü Avatar answered Oct 28 '25 00:10

mert dökümcü



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!