为什么我会从Google Sheets Apps Script收到多个授权请求

huangapple go评论60阅读模式
英文:

Why Do I Get Multiple Authorization Requests from Google Sheets Apps Script

问题

After a few minutes of having authorized the Recorded Macros for a Google Sheets Spreadsheet, I am again asked to reauthorize the project to access my account (still using same browser session).

我在授权了Google Sheets电子表格的Recorded Macros几分钟后,再次被要求重新授权该项目以访问我的账户(仍然使用相同的浏览器会话)。

I visited Google account https://myaccount.google.com/permissions to view "Apps with access to your account," I confirmed the Recorded Macros Apps Script was authorized.

我访问了Google账户 https://myaccount.google.com/permissions 以查看“访问您账户的应用程序”,我确认了Recorded Macros Apps Script已被授权。

As the image below shows, the Recorded Macro appears as "Has access to Google Docs."

如下图所示,Recorded Macro显示为“已访问Google Docs”。

However, when I try to run the Apps Script editor, I get a pop up with the text "Authorization required This project requires your permission to access your data."

然而,当我尝试运行Apps Script编辑器时,弹出一个带有文本“需要授权的授权窗口,该项目需要您的许可才能访问您的数据”。

The content of appsscript.json is below:

appsscript.json的内容如下:

{
"timeZone": "America/Los_Angeles",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"sheets": {
"macros": [
{
"menuName": "First Macro",
"functionName": "FirstMacro"
},
{
"menuName": "ImportHTML",
"functionName": "ImportHTML"
}
]
}
}

Why am I required to authorize the same project multiple times?

为什么我需要多次授权相同的项目?

P.S. Yesterday, I posted this question at the Google Docs forum, but I got no answer, so here I post hoping to get one. Right now, the name of the recorded macro (i.e., Apps Script project name) is "Recorded Macros (Authorized 20230513 Recorded Macro)" Google documentation indicates I post questions related to Apps Script in this forum:

P.S. 昨天,我在Google Docs论坛上发表了这个问题,但没有得到答案,所以我在这里发帖希望能得到答案。目前,录制的宏的名称(即,Apps Script项目名称)是“Recorded Macros (Authorized 20230513 Recorded Macro)” Google文档指示我在此论坛上发布与Apps Script相关的问题。

英文:

After a few minutes of having authorized the Recorded Macros for a Google Sheets Spreadsheet, I am again asked to reauthorized the project to access my account (still using same browser session).

I visited Google account https://myaccount.google.com/permissions to view "Apps with access to your account," I confirmed the Recorded Macros Apps Script was authorized.

As the image below shows, the Recorded Macro appears as "Has access to Google Docs"

为什么我会从Google Sheets Apps Script收到多个授权请求

However, when I try to run the Apps Script editor, I get a pop up with the text "Authorization required This project requires your permission to access your data"

为什么我会从Google Sheets Apps Script收到多个授权请求

The content of appsscript.json is below:

{
  "timeZone": "America/Los_Angeles",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "sheets": {
    "macros": [
      {
        "menuName": "First Macro",
        "functionName": "FirstMacro"
      },
      {
        "menuName": "ImportHTML",
        "functionName": "ImportHTML"
      }
    ]
  }
}

Why am I required to authorize the same project multiple times?

P.S. Yesterday, I posted this question at the Google Docs forum, but I got no answer, so here I post hoping to get one. Right now, the name of the recorded macro (i.e., Apps Script project name) is "Recorded Macros (Authorized 20230513 Recorded Macro)" Google documentation indicates I post questions related to Apps Script in this forum:

1: https://i.stack.imgur.com/tX0gW.png "Google account user interface Security page shows the Apps that have access to the user account (https://myaccount.google.com/permissions). In this case, the scope is limited to Google Docs"
2: https://i.stack.imgur.com/S5GxH.png "Apps Scipt code editor in the background, with modal (i.e., pop up or prompt window) notifying the user that 'Authorization required This project requires your permission to access your data'"

答案1

得分: 2

每当我们包含扩展应用脚本项目功能的代码时,我们将需要对其进行授权。这是由于项目的 SCOPE 发生了变化引起的。

当我发布我的问题时,项目的 OAuth Scopes 已经从 1 个 Scope 请求更改为 2 个 Scopes。

  1. 请求连接到外部服务 https://www.googleapis.com/auth/script.external_request
  2. 查看和管理已安装此应用程序的电子表格 https://www.googleapis.com/auth/spreadsheets.currentonly

在我的情况下,Scope 的变化是由于我在项目代码中使用了 UrlFetchApp 函数引起的。正如在这里所述 https://developers.google.com/apps-script/guides/services/authorization,"Apps Script 根据代码的扫描自动确定授权范围(例如访问您的 Google Sheets 文件或 Gmail)。"

如下面的截图所示,我们可以通过访问项目的概述选项卡并滚动到 "项目 OAuth Scopes" 部分来查看当前的 Scope。

为什么我会从Google Sheets Apps Script收到多个授权请求

Google Apps Script 文档中的类或服务将包括关于其范围的信息。例如,我之前提到了 UrlFetchApp 类,其 文档介绍 中声明:

在同一文档中,继续阅读,我们将找到 授权规范,其中说明:

英文:

Eveytime we include code that extends the functionality of the Apps Script project, we'll be required to authorized it. This happens as a result of the change in SCOPE for the project.

When I posted my question, Project OAuth Scopes had changed from 1 Scope Requested

  • View and manage spreadsheets that this application has been installed
    in https://www.googleapis.com/auth/spreadsheets.currentonly

TO

Project OAuth Scopes 2 Scopes

In my case, the change in scope happened as a result of my use of the UrlFetchApp function within the project's code. As stated here, https://developers.google.com/apps-script/guides/services/authorization , "Apps Script determines the authorization scopes (like access your Google Sheets files or Gmail) automatically, based on a scan of the code."

As the screenshot below illustrates, we can view the current scope by visiting the overview tab of our projects, and scrolling down to the "Project OAuth Scopes" section.

为什么我会从Google Sheets Apps Script收到多个授权请求

The Google Apps Script documentation for the class or service will include information about the scope for it. For example, earlier I mentioned the class UrlFetchApp, and the introduction to the its documentaiton states:

  • This service requires the
    https://www.googleapis.com/auth/script.external_request scope. In
    most cases Apps Script automatically detects and includes the scopes
    a script needs, but if you are setting your scopes explicitly you
    must manually add this scope to use UrlFetchApp.

Within the same document, as we continue to read, we'll find the Authorization specification, which states:

1: https://i.stack.imgur.com/5oM6I.png "Apps Script Project Screenshot shows the Overview Tab of the Project which displays details. At the bottom of the image, an arrow points to the OAuth Scopes section."
2: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
3: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#authorization

huangapple
  • 本文由 发表于 2023年5月13日 14:08:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定