Library function accessed as timed trigger DriveAp

2019-08-03 05:31发布

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?

1条回答
地球回转人心会变
2楼-- · 2019-08-03 06:16

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

查看更多
登录 后发表回答