我从基于时间的触发器调用的Gapps脚本记录了大量错误“我们很抱歉,在从存储区读取错误代码PERMISSION_DENIED时发生了服务器错误”。我假设有用户,他们安装了应用程序和触发器,但后来删除了脚本运行的权限。很明显,这可能会引起这个问题。我还在努力避免.
以下是安装触发器的方式:
var triggerFunction = "processRecurrentLists"; //trigger callback function name
//---------------------------------------------
function createTriggers(tmz) {
// Trigger running at 1am depending on timezone specified in settings
// If no timezone specified, script timezone is used (GMT)
ScriptApp.newTrigger(triggerFunction)
.timeBased()
.everyDays(1)
.inTimezone(tmz)
.atHour(1)
.create();
}
这是触发函数:
function processRecurrentLists() {
// Check if the actions of the trigger requires authorization that has not
// been granted yet; if not, then end - nothing to do.
if (!isScriptAuthorized()) {
console.warn("RecGTasks script is not authorized to run. Please, authorize first.");
return;
}
// ... more code here
}
和功能测试授权:
function isScriptAuthorized() {
try {
var authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
return (authInfo.getAuthorizationStatus() == ScriptApp.AuthorizationStatus.NOT_REQUIRED);
} catch (e) {
console.warn("Script not authorized. err=%s",e.message);
return false;
}
}
我的假设是,如果脚本未被授权且脚本结尾优雅,函数isScriptAuthorized返回false,但情况似乎并非如此。
对此有什么想法吗?
Update 1 I使所有用户都可以访问脚本,作为https://issuetracker.google.com/issues/175139769的解决办法,并在同一天将消息更改为“需要授权才能执行该操作”,因此不再使用PERMISSION_DENIED。进一步调查。
Update 2是的,正如@ziganotschka所指出的,它与V8有关。我使用以下脚本对其进行彻底测试:
function doGet() {
// if trigger not installed
if (ScriptApp
.getProjectTriggers()
.filter(function(t){return t.getHandlerFunction() === "myFunction"})
.length == 0
){
// create trigger firing every 1min
ScriptApp.newTrigger("myFunction")
.timeBased()
.everyMinutes(1)
.create();
}
return HtmlService.createHtmlOutput('<h1>Trigger test installed</h1>');
}
function myFunction() {
Logger.log("Hello from triggered function");
return ("Hello from server");
}
https://stackoverflow.com/questions/65124449
复制