Script fails on SpreadsheetApp.openById - Requires permission

让人想犯罪 __ 提交于 2020-07-09 08:54:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!