Google Drive – Authorization Problem with Google Apps Script

google-apps-scriptgoogle-drive

I made a script that makes a copy of its related Google Form after making a few changes to it. Although I've already authorized the script to modify my Google Drive data, it only works properly when the tab where the scripts is written is opened. I used the onOpen() trigger so the script is supposed to work whenever the page is opened or refreshed.

Here is the code and the error that I'm receiving when I have just the form tab opened:

Code: var pastas =
 DriveApp.getFolderById("xxxxxxxxxxxxxxxxxxxx").getFolders();

Error: Execution failed: You have no permission to call getFolderById
(line 114, file "Código")

What can I do to fix this?

Best Answer

It's very likely you are using a simple trigger rather than an installable trigger. Simple triggers only can call services that do not require authorization to run. For further details see https://developers.google.com/apps-script/guides/triggers/