脚本在SpreadsheetApp.openById上失败-需要权限 [英] Script fails on SpreadsheetApp.openById - Requires permission

查看:246
本文介绍了脚本在SpreadsheetApp.openById上失败-需要权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个onOpen函数,可在电子表格中创建自定义菜单。它已经运行了一年多,但是几天前它停止了工作。

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:

执行失败:您无权调用SpreadsheetApp.openById。所需权限: https://www.googleapis.com/auth/spreadsheets

"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")

我已经检查了启用了哪些API,并且启用了工作表,这反映在.json文件中。我在脚本中的任何地方都没有@OnlyCurrentDoc。我已经为此脚本重置了帐户的权限,再次运行了该功能并允许了权限,但是菜单仍然不会在打开时创建。

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.

我的.json文件:

{
"timeZone": "Europe/London",
"dependencies": {
"enabledAdvancedServices": [{
  "userSymbol": "Sheets",
  "serviceId": "sheets",
  "version": "v4"
 }]
},
"exceptionLogging": "STACKDRIVER"
}


推荐答案

发生此错误是因为代码没有足够的权限来运行该方法。 openById 方法需要一个或多个范围。您的清单.JSON应该如下所示:

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.

这篇关于脚本在SpreadsheetApp.openById上失败-需要权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆