I am having issues with the getFolderById function. I am the owner of the folder in question. The specific call is as follows.
var folder = DriveApp.getFolderById('string_id_of_my_folder');
I am passing the long string of the ID of the folder inside the function. I ran the function inside the editor to make sure permissions have been turned on - and I'm not getting any errors.
But when I try to run the function inside the spreadsheet, I get the following error message: "You do not have permission to call getFolderById".
What am I doing wrong?
The issue here is that custom functions & simple triggers run with limited permissions: you can't perform actions that require user credentials, like reading from another file. These limitations are spelled out here for custom functions & here for simple triggers.
Installable triggers don't have this limitation. So if you needed to access another when you open your current file or from a standalone script, you'll need to install an Open
trigger. Here's Google's documentation.
Without setting the OAuth scopes you get something like below...
So the specific answer to this is you need to set OAuth scopes with this
"https://www.googleapis.com/auth/drive"
in the appscript.json file. To find view this file you need to go to the settings of the App Script project.
Whenever you're using any of the Google API's you need to add the scopes from here. This will then ask you again for permission by logging into your account.
{
"timeZone": "Europe/London",
"dependencies": {
"enabledAdvancedServices": [
{
"userSymbol": "Classroom",
"version": "v1",
"serviceId": "classroom"
}
]
},
"oauthScopes": [
"https://www.googleapis.com/auth/drive",
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"webapp": {
"executeAs": "USER_DEPLOYING",
"access": "MYSELF"
}
}
You should now see something like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With