作为定时触发的库函数触发DriveApp [英] Library function accessed as timed trigger DriveApp

查看:130
本文介绍了作为定时触发的库函数触发DriveApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仍然是Apps Script的新手,仍然有挫折。任何帮助将不胜感激。

场景:
用户A创建了名为batchServices的库脚本



batchServices包含函数weeklyTrigger(),其中包含以下行1299,以创建csv提取:

  var url = DriveApp.getFolderById(folder)
.createFile(filename,csv,MimeType.CSV)
.getDownloadUrl()
.replace(?e = download& gd =真正,);
返回网址;

用户X创建了电子表格S1和S2。用户A(库脚本batchServices的所有者)在脚本编辑器库菜单中以及在API控制台中添加为高级Google服务Google Sheets API。用户A然后将以下脚本添加到S1:

  function weeklyTrigger(){
batchServices.weeklyTrigger();

$ / code>

然后用户A添加了每周触发器的触发器,每周运行一次00:00和01:00。

成功执行触发器和每周批触发器,创建所需的csv输出。

问题:
用户B(不是库脚本的所有者,而是共享读/写的用户访问它)执行完全相同的步骤来将每周批处理服务添加到电子表格S2。请记住,S1和S2实质上是同一电子表格的副本,两者都属于用户X,并且写入权限已扩展到用户A和B.唯一的区别在这两种情况下,用户A拥有库脚本,而用户B只有写入权限。以下是S2每周触发事件触发并正确调用库脚本的类似命名函数时生成的错误报告:

错误消息(重新格式化以符合SO:)
$ b


开始日期:3/5/18 12:32 AM功能:weeklyTrigger错误消息:访问被拒绝:
DriveApp 。 (1299行,文件代码,项目BatchServices)触发:
基于时间结束:3/5/18 12:38 AM

看起来问题是认证之一。是否需要执行额外的步骤来允许用户B(谁不是图书馆脚本的所有者,但有写权限的人)在Spreadsheet S2中编写触发使用DriveApp调用的库函数的触发器?值得注意的是,用户A无法看到用户B在电子表格S2中建立的触发器,而用户B无法看到电子表格S1中由用户A建立的触发器。如何让用户A和B承担相同的权利?

(授予用户B)访问DriveApp文件夹。向前和向上: - )

Still an Apps Script newbie, still having setbacks. Any help would be greatly appreciated.

Scenario: User A created a library script named "batchServices"

batchServices includes function weeklyTrigger() which includes the following Line 1299, to create a csv extract:

var url = DriveApp.getFolderById(folder)
.createFile(filename, csv, MimeType.CSV)
.getDownloadUrl()
.replace("?e=download&gd=true","");
return url;

User X created spreadsheets S1 and S2. User A (the owner of the library script batchServices) added as Advanced Google Services the Google Sheets API in the Script Editor Library menu and also in the API console. User A then added the following script to S1:

function weeklyTrigger() {
  batchServices.weeklyTrigger();
}

User A then added the trigger weeklyTrigger, time driven to run once a week between 00:00 and 01:00.

The trigger fired and the batch weekly trigger successfully executed, creating the required csv output. Hoorah.

The Problem: User B (not the owner of the the library script but a user with shared read/write access to it) performed exactly the same steps to add the weekly batch service to spreadsheet S2 Remember, S1 and S2 are essentially copies of the same spreadsheet, both owned by User X and with write permissions extended to User A and B. The only difference in the two scenarios is that User A owns the library script while User B has only write access. Here is the error report generated when S2’s weekly trigger event fired and correctly invoked the library script’s similarly named function:

Error Message (reformatted to suit SO:)

Start: 3/5/18 12:32 AM Function: weeklyTrigger Error Message: Access denied: DriveApp. (line 1299, file "Code", project "BatchServices") Trigger: time-based End: 3/5/18 12:38 AM

It looks like the problem is one of authentication. Are there extra steps that must be taken to allow User B (who is not the owner of the library script but who has write access) to write a trigger in Spreadsheet S2 that invokes a library function that uses DriveApp calls? Notably, User A cannot see the triggers established in Spreadsheet S2 by User B and User B cannot see the triggers establisged by User A in Spreadsheet S1. How can I make Users A and B assume the same rights please?

解决方案

As commented above the answer was straightforward, I hadn't granted access (to User B) to the DriveApp Folder. Onward and upwards :-)

这篇关于作为定时触发的库函数触发DriveApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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