首页 > 解决方案 > UrlFetchApp 在每次调用时返回错误 404

问题描述

今天突然间,我在使用带有 UrlFetchApp 的脚本时开始收到错误 404,该脚本直到昨天都运行良好。

我的脚本如下:

const url = ScriptApp.getService().getUrl() + "?function=";

function doGet(e) {
  if (e.parameter.function == "Protect") {
    script();
    return ContentService.createTextOutput();
  }
  else if (e.parameter.function == "AddRows" ) {
    Addrows(e.parameter.sheetName,e.parameter.notoAdd);
    return ContentService.createTextOutput();
  }
  else { // do something by default if there are no url parameters
    throw new Error("function was not found.");
    
  }
}

function Protect() {
  UrlFetchApp.fetch(url + "Protect", {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});
}

消息详细信息异常:对https://script.google.com的请求失败,返回代码 404。截断的服务器响应:<meta name="viewport" c...(使用 muteHttpExceptions 选项检查完整响应)

当使用选项 muteHttpExceptions : flase 时,会产生相同的错误。

请让我知道脚本中突然发生了什么变化,因为我在其他各种代码中也遇到了同样的错误。

标签: google-apps-scriptgoogle-sheets

解决方案


推荐阅读