google-sheetsgoogle-apps-scriptyoutubeyoutube-apiyoutube-data-api

Why is the "importchannel" function of this YouTube Data API to Google Sheets Apps Script not working?


Working off Joseph Asinyo's script in this Google Sheet template and every sheet except the Import Channel one is working fine.

Problem: No matter what channel name you enter you get the same output: output screenshot

  1. I assume something needs to be fixed or updated in the "importchannel" section to get the data to populate but am unsure why it isn't working when the others are. This is what I need help solving.

  2. Also wondering if there is a way to change the channel input from "channel name" to "channel handle instead (either the normal @ name or without if the user doesn't type it, perhaps using forHandle or something similar)."

Here is the script:

/**
 * IMPORT FROM YOUTUBE CUSTOM FUNCTIONS
 * 
 * Written with ❤️ by Joseph Asinyo
 */



// IMPORTANT NOTE: Deploy the script as a web app and insert the url below
var WEB_APP_URL = "https://script.google.com/macros/s/**keyhiddenforprivacy**/exec"



// Web Apps using as the wrapper.
function doGet(e) {
  var request_type = e.parameter.request_type
  if(request_type == "importvideo"){
    var res = getVideoData(e.parameter.videoLink)
  } else if(request_type == "importsearch"){
    var res = getSearchData(e.parameter.searchTerm, e.parameter.numberOfVideos)
  } else if(request_type == "importchannel"){
    var res = getChannelData(e.parameter.channelName)
  } else if(request_type == "importchannelvideos"){
    var res = getChannelVideosData(e.parameter.channelName, e.parameter.numberOfVideos)
  } else if(request_type == "importcomments"){
    var res = getCommentsData(e.parameter.videoLink, e.parameter.numberOfComments, e.parameter.getReplies)
  } 

  return ContentService.createTextOutput(JSON.stringify(res));
}



function makeRequestToWebApp(parameters) {
  var url = WEB_APP_URL+"?";

  for (const key of Object.keys(parameters)) {
    url += key+"="+parameters[key]+"&";
  }
  url = url.slice(0, -1); // Remove the last "&" character

  console.log(url)

  var response = UrlFetchApp.fetch(url).getContentText();
  var result = JSON.parse(response).data;

  return result;
}```

Solution

  • SOLVED: Someone on Reddit noticed the issue is not with the script but rather with the Google Sheet formula -

    the IMPORTCHANNEL() formulas in column C of "Import Channel" sheet should be referencing the name in A column of the same row.

    Like C4 currently has this: =if(A4="","", IMPORTCHANNEL(C1))

    When it should be this: =if(A4="","", IMPORTCHANNEL(A4))