使用客户端库为视频添加注释
本快速入门为您介绍 Video Intelligence API。在本快速入门中, 您将设置您的 Google Cloud 项目和授权,然后 请求 Video Intelligence 为视频添加注释。
准备工作
- 登录您的 Google Cloud 账号。如果您是新手 Google Cloud, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Video Intelligence API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Video Intelligence API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
安装客户端库
Go
go get cloud.google.com/go/videointelligence/apiv1
Java
如果您使用的是 Maven,请将以下代码添加到您的 pom.xml 文件中。如需详细了解
BOM,请参阅Google Cloud Platform 库 BOM。
如果您使用的是 Gradle, 请将以下代码添加到您的依赖项中:
如果您使用的是 sbt,请将 以下代码添加到您的依赖项中:
如果您使用的是 Visual Studio Code 或 IntelliJ,可以通过以下 IDE 插件将客户端库添加到您的 项目中:
上述插件还提供其他功能,例如服务账号密钥管理。如需了解详情,请参阅各个插件相应的文档。
Node.js
在安装库之前,请确保已经为 Node.js 开发准备好环境。
npm install @google-cloud/video-intelligence
Python
在安装库之前,请确保已经为 Python 开发准备好环境。
pip install --upgrade google-cloud-videointelligence
其他语言
C#:请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Video Intelligence 参考文档。
PHP:请按照客户端库页面上的PHP 设置说明操作,然后访问PHP 版 Video Intelligence 参考文档。
Ruby:请按照客户端库页面上的Ruby 设置说明操作,然后访问Ruby 版 Video Intelligence 参考文档。
设置身份验证
-
安装 Google Cloud CLI。 安装完成后, 初始化 Google Cloud CLI,方法是运行以下命令:
gcloud init如果您使用的是外部身份提供方 (IdP),则必须先 使用联合身份登录 gcloud CLI。
-
如果您使用的是本地 shell,请为您的用户 账号创建本地身份验证凭证:
gcloud auth application-default login
如果您使用的是 Cloud Shell,则无需执行此操作。
如果返回了身份验证错误,并且您使用的是外部身份提供方 (IdP),请确认您已 使用联合身份登录 gcloud CLI。
登录屏幕随即出现。在您登录后,您的凭据会存储在 ADC 使用的本地凭据文件中。
标签检测
现在,您可以使用 Video Intelligence API 请求视频或视频片段中的信息,例如标签检测。请运行以下代码以执行您的第一个视频标签检测请求:
Go
Java
Node.js
在运行该示例之前,请确保已经为 Node.js 开发准备好环境。
Python
在运行该示例之前,请确保已经为 Python 开发准备好环境。
其他语言
C#:请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Video Intelligence 参考文档。
PHP:请按照客户端库页面上的PHP 设置说明操作,然后访问PHP 版 Video Intelligence 参考文档。
Ruby:请按照客户端库页面上的Ruby 设置说明操作,然后访问Ruby 版 Video Intelligence 参考文档。
恭喜!您已向 Video Intelligence 发送了第一个请求。
结果怎么样?
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
- 使用 Google Cloud console 删除您不需要的项目。