n8n 中文文档

谷歌 OAuth2 通用

本文档包含有关创建用于自定义操作 的通用 Google OAuth2 API 凭证的说明。

先决条件

设置 OAuth

将您的 n8n 凭据连接到 Google 服务需要五个步骤:

  1. 创建 Google Cloud Console 项目。
  2. 启用API。
  3. 配置您的 OAuth 同意屏幕。
  4. 创建您的 Google OAuth 客户端凭据。
  5. 完成您的 n8n 凭证。

创建 Google Cloud Console 项目

首先,创建一个 Google Cloud Console 项目。如果您已经有一个项目,请跳转到下一节:

启用 API

创建项目后,启用您需要访问的 API:

  1. 访问您的Google Cloud Console - 库。确保您处于正确的项目中。
    检查 Google Cloud 顶部导航中的项目下拉列表
  2. 转到APIs & Services > Library API 和服务 > 库。
  3. 搜索并选择您要启用的 API。例如,对于 Gmail 节点,搜索并启用 Gmail API。
  4. 某些集成需要其他 API 或要求您请求访问权限:

    需要 Google Drive API

    以下集成需要 Google Drive API 以及他们自己的 API:

    • Google文档
    • Google 表格
    • Google 幻灯片

    Google Vertex AI API

    除了 Vertex AI API 之外,您还需要启用 Cloud 资源管理器 API。

  5. 选择 ENABLE。

配置您的 OAuth 同意屏幕

如果您之前在 Google Cloud 项目中没有使用过 OAuth,您需要配置 OAuth 同意屏幕:

  1. 访问您的Google Cloud Console - 库。确保您处于正确的项目中。

    检查 Google Cloud 顶部导航中的项目下拉列表

    2. 打开左侧导航菜单并转到 APIs & Services > OAuth consent screen API 和服务 > OAuth 同意屏幕。 Google 会将您重定向至 Google Auth 平台概述页面。 3. 在 Overview 概述 选项卡上选择 Get started 开始使用 以开始配置 OAuth 同意。 4. 输入 App name 应用名称 和 User support email 用户支持电子邮件 以包含在 Oauth 屏幕上。选择 Next 下一步 继续。 5. 对于 Audience 观众,请选择 Internal 内部 以供您组织的 Google 工作区中的用户访问,或为任何拥有 Google 帐户的用户选择 External 外部。有关用户类型的更多信息,请参阅 Google 的用户类型文档。选择 Next 下一步 继续。 6. 选择 Email addresses 电子邮件地址 Google 用于就项目更改与您联系。选择 Next 下一步 继续。 7. 阅读并接受 Google 的用户数据政策。选择 Continue 继续,然后选择 Create 创建。 8. 在左侧菜单中,选择 Branding 品牌推广。 9. 在 Authorized domains 授权域名 部分中,选择 Add domain 添加域名: * 如果您使用n8n的云服务,请添加n8n.cloud * 如果您是自托管,请添加您的 n8n 实例的域。 10. 选择页面底部的 Save 保存。

创建您的 Google OAuth 客户端凭据

接下来,在 Google 中创建 OAuth 客户端凭据:

  1. 访问您的Google Cloud Console。确保您处于正确的项目中。
  2. 在 APIs & Services API 和服务 部分中,选择 Credentials 凭证。
  3. 选择 + Create credentials + 创建凭证 > OAuth client ID OAuth 客户端 ID。
  4. 在 Application type 应用类型 下拉列表中,选择 Web application 网络应用程序。
  5. Google自动生成Name 名称。将 Name 名称 更新为您可以在控制台中识别的内容。
  6. 从您的 n8n 凭证中复制 OAuth Redirect URL OAuth 重定向 URL。将其粘贴到 Google Console 中的 Authorized redirect URIs 授权重定向 URI 中。
  7. 选择 Create 创建。

完成您的 n8n 凭证

在 Google 项目和凭据完全配置后,完成您的 n8n 凭据:

  1. 从 Google 的 OAuth client created OAuth 客户端已创建 模式中,复制 Client ID 客户ID。在您的 n8n 凭证中输入此内容。
  2. 从同一 Google 模式中,复制 Client Secret 客户秘密。在您的 n8n 凭证中输入此内容。
  3. 您必须提供此证书的范围。有关更多信息,请参阅范围。在空格分隔的列表中输入多个范围,例如:

    https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose 4. 在n8n中,选择Sign in with Google 使用 Google 登录以完成您的Google身份验证。 5. Save 保存 您的新凭据。

视频

以下视频演示了上述步骤:

https://www.youtube.com/embed/FBGtpWMTppw

范围

Google 服务有一个或多个可能的访问作用域。作用域限制用户可以执行的操作。有关所有服务的作用域列表,请参考 Google API 的 OAuth 2.0 作用域。

n8n 不支持所有作用域。创建通用 Google OAuth2 API 凭据时,您可以从下面的 支持的作用域 列表中输入作用域。如果您输入 n8n 尚不支持的作用域,它将无法工作。

支持的范围 |服务 |可用范围 | | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |邮箱 |
  • https://www.googleapis.com/auth/gmail.labels
  • https://www.googleapis.com/auth/gmail.addons.current.action.compose
  • https://www.googleapis.com/auth/gmail.addons.current.message.action
  • https://mail.google.com/
  • https://www.googleapis.com/auth/gmail.modify
  • https://www.googleapis.com/auth/gmail.compose
| |谷歌广告 |
  • https://www.googleapis.com/auth/adwords
| |谷歌分析 |
  • https://www.googleapis.com/auth/analytics
  • https://www.googleapis.com/auth/analytics.readonly
| |谷歌 BigQuery |
  • https://www.googleapis.com/auth/bigquery
| |谷歌图书 |
  • https://www.googleapis.com/auth/books
| |谷歌日历 |
  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.events
| |

Google Cloud
自然语言

|
  • https://www.googleapis.com/auth/cloud-language
  • https://www.googleapis.com/auth/cloud-platform
| |

Google Cloud
存储

|
  • https://www.googleapis.com/auth/cloud-platform
  • https://www.googleapis.com/auth/cloud-platform.read-only
  • https://www.googleapis.com/auth/devstorage.full_control
  • https://www.googleapis.com/auth/devstorage.read_only
  • https://www.googleapis.com/auth/devstorage.read_write
| |谷歌联系人 |
  • https://www.googleapis.com/auth/contacts
| |谷歌文档 |
  • https://www.googleapis.com/auth/documents
  • https://www.googleapis.com/auth/drive
  • https://www.googleapis.com/auth/drive.file
| |谷歌云端硬盘 |
  • https://www.googleapis.com/auth/drive
  • https://www.googleapis.com/auth/drive.appdata
  • https://www.googleapis.com/auth/drive.photos.readonly
| |

Google Firebase
Cloud Firestore

|
  • https://www.googleapis.com/auth/datastore
  • https://www.googleapis.com/auth/firebase
| |

Google Firebase
实时数据库

|
  • https://www.googleapis.com/auth/userinfo.email
  • https://www.googleapis.com/auth/firebase.database
  • https://www.googleapis.com/auth/firebase
| |谷歌视角|
  • https://www.googleapis.com/auth/userinfo.email
| |谷歌表格 |
  • https://www.googleapis.com/auth/drive.file
  • https://www.googleapis.com/auth/spreadsheets
| |谷歌幻灯片|
  • https://www.googleapis.com/auth/drive.file
  • https://www.googleapis.com/auth/presentations
| |谷歌任务 |
  • https://www.googleapis.com/auth/tasks
| |谷歌翻译 |
  • https://www.googleapis.com/auth/cloud-translation
| | GSuite 管理员 |
  • https://www.googleapis.com/auth/admin.directory.group
  • https://www.googleapis.com/auth/admin.directory.user
  • https://www.googleapis.com/auth/admin.directory.domain.readonly
  • https://www.googleapis.com/auth/admin.directory.userschema.readonly
|

故障排除

Google 尚未验证此应用

如果使用 OAuth 身份验证方法,您可能会看到警告 Google hasn't verified this app Google 尚未验证此应用。为了避免这种情况:

  • 如果您的应用User Type 用户类型是Internal 内部,请从您要身份验证的同一账户创建OAuth凭据。
  • 如果您的应用User Type 用户类型是External 外部,您可以将您的电子邮件添加到应用的测试者列表中:转到Audience 受众群体{:target=_blank .external-link}页面,并将您登录时使用的电子邮件添加到Test users 测试用户列表中。

如果您需要使用由其他账户(开发者或其他第三方)生成的凭据,请按照 Google Cloud 文档 | 授权错误:Google 尚未验证此应用{:target=_blank .external-link}中的说明操作。

Google Cloud 应用程序未经授权

对于 Publishing status 发布状态 设置为 Testing 测试 和 User type 用户类型 设置为 External 外部 的 Google Cloud 应用,同意和令牌将在 7 天后过期。参考Google云平台控制台帮助|设置 OAuth 同意屏幕 了解更多信息。要解决此问题,请在 n8n 凭据模式中重新连接应用程序。

不想自己部署和维护 n8n?n8ncn 托管 n8n 云服务:开通账号即可使用,不用买服务器;也可以在 n8ncn 工作流库 找现成的中文工作流。