触发其他用户在GAS Web应用中执行失败 [英] Trigger execution failure in GAS web app by other users

查看:53
本文介绍了触发其他用户在GAS Web应用中执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个网络应用程序,将我的Google驱动器文件夹复制到其他用户的驱动器.为了解决执行时间超过错误的问题,我正在尝试为一个函数创建一个触发器,并使该函数在几分钟后启动.此网络应用将由其他用户执行,因此我将执行为"设置为用户访问网络应用"以及谁有权访问"到拥有Google帐户的任何人".

I made a web app to copy my google drive folders to other users' drive. To solve the execution time exceed error, I'm trying to create a trigger for a function and make the function start after several minutes. This web app will be executed by other users so I set "Execute as" to "User accessing the web app" and "Who has access" to "Anyone with Google account".

当我(此Web应用程序的创建者)运行Web应用程序时,它可以按预期工作,但在由其他用户执行时失败.由于看不到我的执行"中的任何信息,因此我看不到任何有关此失败的日志.应用程序创建者和用户的Apps脚本仪表板的功能.

It works as expected when I(the creator of this web app) run the web app but fails when executed by other users. I cannot see any log for this failure since there is no information available at "My Executions" of Apps Script dashboard of both the app creator and users.

我试图将执行流记录到日志表中,但是执行一开始就失败了,因为无法为执行记录任何内容.

I tried to log the execution flow into log sheet, but the execution fails at the very beginning since nothing couldn't be logged for the execution.

如何让其他用户在其权限下运行触发的功能?

How can I make other users run the triggered function by their permission?

下面是一个示例代码,用于测试其他用户的触发和执行.(由于该问题,我删除了所有用于缓存的代码)

Below is a sample code for testing the trigger and execution by other users. (I removed all code for cache since it is relevant to this issue)

const deleteTrigger = (functionName) => {
  ScriptApp.getProjectTriggers().forEach((t) => {
    ScriptApp.deleteTrigger(t);
  });
};


function doGet(e) {
  Logger.log(e.parameter);
  return HtmlService.createHtmlOutputFromFile('index');
}

function myFunction() {
  ScriptApp.newTrigger('reStart')
    .timeBased()
    .after(3 * 60 * 1000)
    .create();
}

function reStart() {
  deleteTrigger();
}

index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  <div>
  <button id="myFunction">myFunction, make trigger</button><br>
  <button id="reStart">reStart by manual</button><br>
  <button id="deleteTrigger">Delete Trigger</button>
  
  <script>
  document.getElementById('myFunction').addEventListener('click', function() {
    google.script.run.myFunction();
  });
  document.getElementById('reStart').addEventListener('click', function() {
    google.script.run.reStart();
  });
  document.getElementById('deleteTrigger').addEventListener('click', function() {
    google.script.run.deleteTrigger();
  });
  </script>
  </body>
</html>

推荐答案

在花了很多时间和精力之后,我发现基于时间的触发器在V8中不起作用.

After spending useless time and efforts, I found out the time-based trigger is not working in V8.

查看 https://groups.google.com/g/google-apps-script-community/c/VTPmr05Gs8k/m/vdH7jWTfBwAJ 了解详情.

这篇关于触发其他用户在GAS Web应用中执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆