我尝试使用UrlFetch和授权标头中的承载从第二个GAS调用部署的Apps脚本(作为Web应用程序,可由"任何人"访问)时遇到HTTP 401错误.脚本工作正常,持续数周,直到大约两周前.这是两个重现错误的小脚本.
脚本A - 部署为Web应用程序,可供"任何人"访问.
function doGet(e) {
var params = e.parameter.params;
console.info("Parameters : " + JSON.stringify(e.parameter));
return ContentService.createTextOutput("Success");
}
Run Code Online (Sandbox Code Playgroud)
脚本B - 通过UrlFetch调用脚本A.
function callURL() {
var param = {
method : "get",
headers : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
followRedirects : true,
muteHttpExceptions:true,
};
var url = "https://script.google.com/macros/s/<script_A_deployed_url>/exec?param1=test";
var resp = UrlFetchApp.fetch(url,param);
if(resp.getContentText() != "Success"){
console.info(resp.getContentText());
throw resp.getContentText();
}
}
Run Code Online (Sandbox Code Playgroud)