长时间运行的操作
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Video Intelligence API 的某些方法会返回长时间运行的操作。这些方法是异步执行的;当方法返回响应时,操作可能尚未完成。
获取操作状态
您可以使用操作名称检查长时间运行的任务(检测镜头变化)的状态。
REST
在使用任何请求数据之前,请先进行以下替换:
- OPERATION_NAME:从 Video Intelligence API 调用返回的
name
字段。值的格式为:
projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
,
,其中:- PROJECT_NUMBER 是您的 Google Cloud 项目的编号,
- LOCATION_ID 是进行注释的云地区(例如:
us-east1
、us-west1
、europe-west1
、asia-east1
),
- OPERATION_ID 是长时间运行的操作的 ID。
HTTP 方法和网址:
GET https://videointelligence.googleapis.com/v1/OPERATION_NAME
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER" \
"https://videointelligence.googleapis.com/v1/OPERATION_NAME"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://videointelligence.googleapis.com/v1/OPERATION_NAME" | Select-Object -Expand Content
您应会收到如下所示的 JSON 响应:
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1p3beta1.AnnotateVideoProgress",
"annotationProgress": [
{
"inputUri": "INPUT_URI",
"progressPercent": 100,
"startTime": "2020-05-12T19:36:09.110351Z",
"updateTime": "2020-05-12T19:36:17.519069Z"
}
]
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1p3beta1.AnnotateVideoResponse",
"annotationResults": [
{
...
}
]
}
}
取消操作
您可以利用操作 ID 取消长时间运行的操作。但是,无法保证成功取消。
REST
在使用任何请求数据之前,请先进行以下替换:
- OPERATION_ID:在启动操作时在响应中提供,
例如 projects/754177431483/locations/us-west1/operations/3326639765503758657
中的 3326639765503758657
- 注意:
- PROJECT_NUMBER:您的 GCP 项目 ID
- LOCATION_ID:在其中添加注释的 Cloud 区域。支持的云区域为:
us-east1
、us-west1
、europe-west1
、asia-east1
。如果未指定区域,系统将根据视频文件位置确定区域。
HTTP 方法和网址:
POST https://videointelligence.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID:cancel
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://videointelligence.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID:cancel"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://videointelligence.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID:cancel" | Select-Object -Expand Content
您应该会收到一个成功的状态代码 (2xx) 和一个空响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-24。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-01-24。"],[],[]]