启用 Google API OAuth 范围

Poo*_*lve 2 google-api google-apps-script google-drive-api google-oauth

对于使用 Google Apps Script 创建的应用程序之一,一些范围会自动添加到我的应用程序中,如下所示:

https://www.googleapis.com/auth/drive

https://www.googleapis.com/auth/script.external_request

https://www.googleapis.com/auth/script.send_mail

https://www.googleapis.com/auth/spreadsheets

我已根据此文档遵循 OAuth 客户端验证的所有步骤。但是,我的验证过程仍在等待中,支持团队说我需要将https://www.googleapis.com/auth/drive.file范围添加到我的项目中。

任何人都知道如何在现有项目中添加/启用https://www.googleapis.com/auth/drive.file范围。

DaI*_*mTo 5

当您对应用程序进行身份验证时,您应该请求额外的范围

  1. 在 Apps 脚本编辑器中打开脚本项目。
  2. 在菜单中,选择文件 > 项目属性。
  3. 选择范围选项卡。
  4. 查看您的脚本当前需要的范围并确定需要进行哪些更改。完成后单击取消。
  5. 如果清单文件 appsscript.json 在左侧导航栏中不可见,请选择“查看”>“显示清单文件”菜单项。
  6. 在左侧导航中选择 appsscript.json 文件将其打开。
  7. 找到标记为 oauthScopes 的顶级字段。如果它不存在,您可以添加它。
  8. oauthScopes 字段指定一个字符串数组。

例子

{
  ...
  "oauthScopes": [
    " https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/userinfo.email"
  ],
}
Run Code Online (Sandbox Code Playgroud)

检查文档here