Skip to content

谷歌:OAuth2 单一服务(Google: OAuth2 single service)#

本文件包含为单个服务创建 Google 凭证的说明。它们也可以通过视频获取。

🌐 This document contains instructions for creating a Google credential for a single service. They're also available as a video.

Note for n8n Cloud users

For the following nodes, you can authenticate by selecting Sign in with Google in the OAuth section:

先决条件(Prerequisites)#

设置 OAuth(Set up OAuth)#

将 n8n 凭据连接到 Google 服务共有五个步骤:

🌐 There are five steps to connecting your n8n credential to Google services:

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

创建 Google Cloud Console 项目(Create a Google Cloud Console project)#

首先,创建一个 Google Cloud 控制台项目。如果你已经有项目,可以跳到下一部分

🌐 First, create a Google Cloud Console project. If you already have a project, jump to the next section:

  1. Log in to your Google Cloud Console using your Google credentials.
  2. In the top menu, select the project dropdown in the top navigation and select New project or go directly to the New Project page.
  3. Enter a Project name and select the Location for your project.
  4. Select Create.
  5. Check the top navigation and make sure the project dropdown has your project selected. If not, select the project you just created.

    The project dropdown in the Google Cloud top navigation
    Check the project dropdown in the Google Cloud top navigation

启用 API(Enable APIs)#

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

🌐 With your project created, enable the APIs you'll need access to:

  1. Access your Google Cloud Console - Library. Make sure you're in the correct project.
    The project dropdown in the Google Cloud top navigation
    Check the project dropdown in the Google Cloud top navigation
  2. Go to APIs & Services > Library.
  3. Search for and select the API(s) you want to enable. For example, for the Gmail node, search for and enable the Gmail API.
  4. Some integrations require other APIs or require you to request access:

    Google Drive API required

    The following integrations require the Google Drive API, as well as their own API:

    • Google Docs
    • Google Sheets
    • Google Slides

    Google Vertex AI API

    In addition to the Vertex AI API you will also need to enable the Cloud Resource Manager API.

  5. Select ENABLE.

如果你以前没有在谷歌云项目中使用过 OAuth,你需要配置 OAuth 同意屏幕

🌐 If you haven't used OAuth in your Google Cloud project before, you'll need to configure the OAuth consent screen:

  1. 访问你的 Google Cloud 控制台 - 库。确保你在正确的项目中。
    Google Cloud 顶部导航中的项目下拉菜单
    检查 Google Cloud 顶部导航中的项目下拉菜单
  2. 打开左侧导航菜单,进入 APIs 与服务 > OAuth 同意屏幕。Google 会将你重定向到 Google 认证平台概览页面。
  3. 概览 选项卡上选择 开始使用 以开始配置 OAuth 同意。
  4. 输入 应用名称用户支持邮箱 以显示在 OAuth 屏幕上。选择 下一步 继续。
  5. 对于受众,选择内部以便组织内 Google Workspace 用户访问,或选择外部以便任何拥有 Google 账户的用户访问。有关用户类型的更多信息,请参阅 Google 的用户类型文档。选择下一步以继续。
  6. 选择 Google 用于联系你有关项目更改的电子邮件地址。选择下一步继续。
  7. 阅读并接受谷歌的用户数据政策。选择 继续,然后选择 创建
  8. 在左侧菜单中,选择 品牌
  9. 授权域 部分,选择 添加域
    • 如果你正在使用 n8n 的云服务,请添加 n8n.cloud
    • 如果你是自托管,请添加你的 n8n 实例的域名。
  10. 在页面底部选择 保存

创建你的 Google OAuth 客户端凭据(Create your Google OAuth client credentials)#

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

🌐 Next, create the OAuth client credentials in Google:

  1. 访问你的Google Cloud 控制台。确保你处于正确的项目中。
  2. APIs 和服务 部分,选择 凭据
  3. 选择 + 创建凭据 > OAuth 客户端 ID
  4. 应用类型 下拉菜单中,选择 Web 应用
  5. Google 会自动生成一个名称。请将名称更新为你在控制台中能认出的名称。
  6. 如果你是自托管: 从你的 n8n 凭证中复制 OAuth 重定向 URL。将其粘贴到 Google 控制台的 授权重定向 URI 中。如果你使用的是 n8n 云,可以将此字段留空,因为 OAuth 设置已预配置,并且回调 URL 对该配置是固定的。
  7. 选择 创建

完成 n8n 凭据(Finish your n8n credential)#

完成 Google 项目和凭据配置后,完成 n8n 凭据配置:

🌐 With the Google project and credentials fully configured, finish the n8n credential:

  • 如果自托管: 1. 在 Google 的 OAuth 客户端创建 弹窗中,复制 客户端 ID。将其输入到你的 n8n 凭证中。 1. 从相同的 Google 模态中,复制 客户端密钥。在你的 n8n 凭证中输入此信息。
  • 如果使用 n8n 云: 1. 在 n8n 中,选择 使用 Google 登录 来完成你的 Google 身份验证。 1. 保存你的新凭据。

视频(Video)#

故障排除(Troubleshooting)#

Google 尚未验证此信息应用(Google hasn't verified this app)#

If using the OAuth authentication method, you might see the warning Google hasn't verified this app. To avoid this:

  • If your app User Type is Internal, create OAuth credentials from the same account you want to authenticate.
  • If your app User Type is External, you can add your email to the list of testers for the app: go to the Audience page and add the email you're signing in with to the list of Test users.

If you need to use credentials generated by another account (by a developer or another third party), follow the instructions in Google Cloud documentation | Authorization errors: Google hasn't verified this app.

Google Cloud 应用未授权(Google Cloud app becoming unauthorized)#

For Google Cloud apps with Publishing status set to Testing and User type set to External, consent and tokens expire after seven days. Refer to Google Cloud Platform Console Help | Setting up your OAuth consent screen for more information. To resolve this, reconnect the app in the n8n credentials modal.