Google:OAuth2 通用(Google: OAuth2 generic)#
本文件包含用于创建通用 OAuth2 Google 凭证以供 自定义操作 使用的说明。
🌐 This document contains instructions for creating a generic OAuth2 Google credential for use with custom operations.
Note for n8n Cloud users
For the following nodes, you can authenticate by selecting Sign in with Google in the OAuth section:
先决条件(Prerequisites)#
- 创建一个 Google Cloud 账户。
设置 OAuth(Set up OAuth)#
将 n8n 凭据连接到 Google 服务共有五个步骤:
🌐 There are five steps to connecting your n8n credential to Google services:
创建 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:
- Log in to your Google Cloud Console using your Google credentials.
- In the top menu, select the project dropdown in the top navigation and select New project or go directly to the New Project page.
- Enter a Project name and select the Location for your project.
- Select Create.
-
Check the top navigation and make sure the project dropdown has your project selected. If not, select the project you just created.
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:
- Access your Google Cloud Console - Library. Make sure you're in the correct project.
Check the project dropdown in the Google Cloud top navigation - Go to APIs & Services > Library.
- Search for and select the API(s) you want to enable. For example, for the Gmail node, search for and enable the Gmail API.
-
Some integrations require other APIs or require you to request access:
- Google Perspective: Request API Access.
- Google Ads: Get a Developer Token.
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.
-
Select ENABLE.
配置 OAuth 授权页面(Configure your OAuth consent screen)#
如果你以前没有在谷歌云项目中使用过 OAuth,你需要配置 OAuth 同意屏幕:
🌐 If you haven't used OAuth in your Google Cloud project before, you'll need to configure the OAuth consent screen:
- 访问你的 Google Cloud 控制台 - 库。确保你在正确的项目中。
检查 Google Cloud 顶部导航中的项目下拉菜单 - 打开左侧导航菜单,进入 APIs 与服务 > OAuth 同意屏幕。Google 会将你重定向到 Google 认证平台概览页面。
- 在 概览 选项卡上选择 开始使用 以开始配置 OAuth 同意。
- 输入 应用名称 和 用户支持邮箱 以显示在 OAuth 屏幕上。选择 下一步 继续。
- 对于受众,选择内部以便组织内 Google Workspace 用户访问,或选择外部以便任何拥有 Google 账户的用户访问。有关用户类型的更多信息,请参阅 Google 的用户类型文档。选择下一步以继续。
- 选择 Google 用于联系你有关项目更改的电子邮件地址。选择下一步继续。
- 阅读并接受谷歌的用户数据政策。选择 继续,然后选择 创建。
- 在左侧菜单中,选择 品牌。
- 在 授权域 部分,选择 添加域:
- 如果你正在使用 n8n 的云服务,请添加
n8n.cloud - 如果你是自托管,请添加你的 n8n 实例的域名。
- 如果你正在使用 n8n 的云服务,请添加
- 在页面底部选择 保存。
创建你的 Google OAuth 客户端凭据(Create your Google OAuth client credentials)#
接下来,在 Google 中创建 OAuth 客户端凭据:
🌐 Next, create the OAuth client credentials in Google:
- 访问你的Google Cloud 控制台。确保你处于正确的项目中。
- 在 APIs 和服务 部分,选择 凭据。
- 选择 + 创建凭据 > OAuth 客户端 ID。
- 在 应用类型 下拉菜单中,选择 Web 应用。
- Google 会自动生成一个名称。请将名称更新为你在控制台中能认出的名称。
- 从你的 n8n 凭证中,复制 OAuth 重定向 URL。将其粘贴到 Google 控制台的 授权重定向 URI 中。
- 选择 创建。
完成 n8n 凭据(Finish your n8n credential)#
完成 Google 项目和凭据配置后,完成 n8n 凭据配置:
🌐 With the Google project and credentials fully configured, finish the n8n credential:
- 在 Google 的 OAuth 客户端创建 弹窗中,复制 客户端 ID。将其输入到你的 n8n 凭证中。
- 从相同的 Google 模态中,复制 客户端密钥。在你的 n8n 凭证中输入此信息。
-
您必须为此凭证提供作用域。有关更多信息,请参阅 Scopes。请输入多个作用域,并以空格分隔,例如:
1https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose -
在 n8n 中,选择 使用 Google 登录 来完成你的 Google 身份验证。
- 保存你的新凭据。
视频(Video)#
以下视频演示了上述步骤:
🌐 The following video demonstrates the steps described above:
作用域(Scopes)#
谷歌服务可能有一个或多个访问范围。范围限制了用户可以执行的操作。有关所有服务范围的列表,请参阅 Google API 的 OAuth 2.0 范围。
🌐 Google services have one or more possible access scopes. A scope limits what a user can do. Refer to OAuth 2.0 Scopes for Google APIs for a list of scopes for all services.
n8n 并不支持所有的权限范围。在创建通用的 Google OAuth2 API 凭证时,你可以从下面的 支持的权限范围 列表中输入权限范围。如果你输入 n8n 尚未支持的权限范围,它将无法工作。
🌐 n8n doesn't support all scopes. When creating a generic Google OAuth2 API credential, you can enter scopes from the Supported scopes list below. If you enter a scope that n8n doesn't already support, it won't work.
Supported scopes
| Service | Available scopes |
|---|---|
| Gmail |
|
| Google Ads |
|
| Google Analytics |
|
| Google BigQuery |
|
| Google Books |
|
| Google Calendar |
|
| Google Cloud Natural Language |
|
| Google Cloud Storage |
|
| Google Contacts |
|
| Google Docs |
|
| Google Drive |
|
| Google Firebase Cloud Firestore |
|
| Google Firebase Realtime Database |
|
| Google Perspective |
|
| Google Sheets |
|
| Google Slide |
|
| Google Tasks |
|
| Google Translate |
|
| GSuite Admin |
|
故障排除(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.