在使用 Google API 之前,您需要在 Google Cloud 项目中启用这些 API。您可以在单个 Google Cloud 项目中启用一个或多个 API。 如果您还没有 Google Cloud 项目,请参阅创建 Cloud 项目。
如需在 Cloud 项目中启用 API,请执行以下操作:
Google Cloud 控制台
- 在 Google Cloud 控制台中,依次点击“菜单” > API 和服务 > 库 > Google Workspace。
- 点击您要启用的 API。
- 点击启用。
- 如需启用更多 API,请重复上述步骤。
Google Cloud CLI
- 安装或打开 Google Cloud 命令行界面 (CLI)。
-
运行
services enable命令,指定要启用的 API 服务。gcloud services enable API_SERVICE_ID
Google AI Studio 中预先启用的 API
在 Google AI Studio 中构建 Web 应用时,您无需在 Google Cloud 控制台中手动启用受支持的 Google Workspace API。以下 API 已在 Google 管理的新手体验层级项目中预先启用:
- Google Calendar API (
calendar-json.googleapis.com) - Google Docs API (
docs.googleapis.com) - Google Drive API (
drive.googleapis.com) - Google Forms API (
forms.googleapis.com) - Gmail API (
gmail.googleapis.com) - Google Picker API (
picker.googleapis.com) - Google Sheets API (
sheets.googleapis.com) - Google Slides API (
slides.googleapis.com) - Google Tasks API (
tasks.googleapis.com)
在新手体验层级项目中,Google Workspace API 仅支持客户端 OAuth 2.0。例如,Google Picker API 使用 OAuth 2.0 访问令牌,而不是开发者 API 密钥,并且不支持服务账号或在 Secret Manager 中存储 OAuth 客户端密钥。如果您需要服务器端凭据、API 密钥或其他 API(例如 Admin SDK API 或 Google Apps 脚本 API),可以将新手体验层级项目升级为标准云项目,然后手动配置这些凭据、密钥或 API。
如需详细了解新手体验层级的配额和功能,请参阅新手体验层级概览和从 Google AI Studio 部署 Web 应用。
(可选)在实验性应用中试用 Google Workspace API
如果您正在试用 Google Workspace,请使用以下快捷方式,该快捷方式会启用常用的 Google Workspace API,并创建可供您使用的 OAuth 凭据。
如果您正在开发一款会访问用户信息应用,则必须在发布应用之前配置 OAuth 权限请求页面。
点击此按钮可选择或创建 Google Cloud 项目,并自动启用 Workspace API:
在随即显示的对话框中,点击下载客户端配置,并将credentials.json 保存到工作目录。
如需查看所有可用 API 的完整列表,并从浏览器中试用特定方法,请参阅 Google Workspace API Explorer。
已启用的 API(点击可展开)
该按钮会启用以下 API:
- Admin SDK/API
- Apps Script API
- Calendar API
- Chat API
- Classroom API
- Docs API
- Drive API
- Forms API
- Gmail API
- Google Workspace Add-ons API
- Google Keep API
- Meet REST API
- Sheets API
- Slides API
Google Workspace API
使用以下 Google Cloud 控制台链接或 Google Cloud 命令行界面 (CLI) 在云项目中启用特定的 Google Workspace API。
Admin SDK API |
启用 Admin SDK API
|
Alert Center API |
启用 Alert Center API
|
Apps Script API |
启用 Apps 脚本 API
|
CalDAV API |
启用 CalDAV API
|
Calendar API |
启用 Calendar API
|
Chat API |
启用 Chat API
|
Classroom API |
启用 Classroom API
|
Cloud Identity API |
启用 Cloud Identity API
|
Cloud Search API |
启用 Cloud Search API
|
Docs API |
启用 Docs API
|
Drive API |
启用 Drive API
|
Drive Activity API |
启用 Drive Activity API
|
Drive Labels API |
启用 Drive Labels API
|
Forms API |
启用 Forms API
|
Gmail API |
启用 Gmail API
|
Groups Migration API |
启用 Groups Migration API
|
Groups Settings API |
启用 Groups Settings API
|
Google Workspace Add-ons API |
启用 Google Workspace Add-ons API
|
Google Keep API |
启用 Google Keep API
|
Enterprise License Manager API |
启用 Enterprise License Manager API
|
Marketplace API |
启用 Marketplace API
|
Marketplace SDK |
启用 Marketplace SDK
|
Meet REST API |
启用 Meet REST API
|
People API |
启用 People API
|
Postmaster Tools API |
启用 Postmaster Tools API
|
Reseller API |
启用 Reseller API
|
Sheets API |
启用 Sheets API
|
Slides API |
启用 Slides API
|
Tasks API |
启用 Tasks API
|
Vault API |
启用 Vault API
|