问题
I have an onOpen function that creates a custom menu in a spreadsheet. It's been working fine for over a year, but a couple days ago it stopped working.
When I look at the execution transcript I get:
"Execution failed: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets"
This fails/relates to the below line of code:
var ss = SpreadsheetApp.openById("myID")
I've checked what API's are enabled, and I have Sheets enabled, which is reflected in the .json file. I don't have @OnlyCurrentDoc anywhere in the script. I've reset the permissions on the account for this script, ran the function again and allowed permissions, but still the menu will not create on open.
My .json file:
{
"timeZone": "Europe/London",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Sheets",
"serviceId": "sheets",
"version": "v4"
}]
},
"exceptionLogging": "STACKDRIVER"
}
回答1:
This error occurs because the code doesn't have enough permissions to run that method. The openById
method requires one or more of this scopes. Your manifest .JSON should look like this:
{
"timeZone": "Europe/London",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Sheets",
"serviceId": "sheets",
"version": "v4"
}]
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets"
]
}
Notice how I added the scope at the end of the file. Please, don't hesitate to ask for more clarification to this answer.
来源:https://stackoverflow.com/questions/58025650/script-fails-on-spreadsheetapp-openbyid-requires-permission