Reputation: 41
I keep getting the following error when I run a Google apps script:
Execution failed: You do not have permission to call getFoldersByName
Here is the line of code I'm running:
var folders = DriveApp.getFoldersByName('Mission Response');
When I run the script from Script editor it runs without any problems. However, I never get the authorization dialog (the one that authorizes DriveApp). When I run the script from inside the spreadsheet, the script fails with the execution error above.
Upvotes: 4
Views: 544
Reputation: 7373
After a lot of struggle, I found the solution on this link.
It states that you cannot use services that require authentication with simple triggers, like onEdit()
.
Knowing that, I did this to solve it:
I had something like:
function onEdit(){
var folder = DriveApp.gefFoldersByName('My Folder Name').next();
doSomething(folder);
...
}
Then I created the installable trigger:
function onEditTrigger(){
var folder = DriveApp.gefFoldersByName('My Folder Name').next();
doSomething(folder);
...
}
I hope it helps, as it took me a lot of time to figure out.
Upvotes: 1