Home > Mobile >  How to get YouTube channels' topic categories in bulk with Google Apps Script?
How to get YouTube channels' topic categories in bulk with Google Apps Script?

Time:11-01

I have a list that contains around 10,000 YouTube channels - got it from Google Ads. I want to get each channel's topic category into a new column. How can I do this?

CodePudding user response:

Before proceeding to the code, make sure:

  • You enabled YouTube Data API v3 for your Google Cloud Project and created an API key. Please see the getting started document if needed.
  • Create the "importjson.gs" file for your Google Apps Script project and paste this code into it.

Once you're done with the preliminary steps, you can proceed to the following code: It creates the function GET_CHANNEL_TOPIC_CATEGORIES, which takes the channel URL as an input and returns the channel topic categories.

Here is the code:

var API_KEY='YOUR_API_KEY'
var CHANNELS_URL = 'https://www.googleapis.com/youtube/v3/channels'
var PLAYLIST_ITEMS_URL = 'https://youtube.googleapis.com/youtube/v3/playlistItems'
var VIDEOS_URL =  'https://youtube.googleapis.com/youtube/v3/videos'

function GET_CHANNEL_TOPIC_CATEGORIES(channel_url){
    channel_id = channel_url.replace("http://youtube.com/channel/", "")
    url_uploads_id = CHANNELS_URL   "?part=topicDetails&id="   channel_id   "&key="   API_KEY;
    return ImportJSON(url_uploads_id, "/items/topicDetails/topicCategories", "noHeaders")
}
  • Related