You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script无法自动请求SpreadsheetApp及ScriptApp所需OAuth权限咨询

Google Apps Script无法自动请求权限,需手动编辑appsscript.json的问题

问题描述

我多次构建过同类脚本,但最近遇到异常:用于读取Google Sheet数据并发送邮件的脚本,无法自动请求访问电子表格和管理触发器所需的权限,运行时反复报错。

报错详情

  • 电子表格访问错误:

Exception: You do not have permission to call SpreadsheetApp.getActiveSpreadsheet. Required permissions: https://www.googleapis.com/auth/spreadsheets

  • 触发器管理错误:

Exception: Specified permissions are not sufficient to call ScriptApp.getProjectTriggers. Required permissions: https://www.googleapis.com/auth/script.scriptapp

临时解决方案

目前仅能通过手动编辑appsscript.json清单文件,显式声明所需权限解决问题,可正常运行的清单文件如下:

{
  "timeZone": "America/Toronto",
  "dependencies": {
    "enabledAdvancedServices": [
      {
        "userSymbol": "Drive",
        "version": "v3",
        "serviceId": "drive"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/spreadsheets",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/drive.readonly",
    "https://www.googleapis.com/auth/gmail.send",
    "https://www.googleapis.com/auth/script.scriptapp"
  ],
  "sheets": {
    "macros": [
      {
        "menuName": "Untitled Macro",
        "functionName": "UntitledMacro"
      }
    ]
  }
}

疑问

Apps Script本应自动处理这些权限,该行为疑似Bug,且多个脚本均出现此问题,并非个案。想请教:

  • 这是已知问题吗?
  • 是否存在比手动编辑清单更持久的解决方案?

内容的提问来源于stack exchange,提问作者Mr. M. Perzan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 09:33:19