获取操作状态

通过批量导入创建商品集、完全清除商品集以及完全清除孤立的商品等多项请求操作是长时间运行的操作。这些类型的请求将返回包含操作 ID 的 JSON,您可以使用该 ID 来获取操作的状态。

例如,批量删除 (purge) 请求会返回以下 JSON:

{
"name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626"
}

在本例中,操作 ID 为 bc4e1d412863e626。以下示例展示了如何使用此 ID 获取相应操作的状态。

REST

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID。
  • LOCATION_ID:有效的位置标识符。有效的位置标识符包括 us-west1us-east1europe-west1asia-east1
  • OPERATION_ID:您的操作的 ID。此 ID 是操作名称的最后一个元素。例如:
    • 操作名称:projects/PROJECT_ID/locations/LOCATION_ID/operations/bc4e1d412863e626
    • 操作 ID:bc4e1d412863e626

HTTP 方法和网址:

GET https://vision.googleapis.com/v1/locations/location-id/operations/operation-id

如需发送请求,请选择以下方式之一:

curl

执行以下命令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://vision.googleapis.com/v1/locations/location-id/operations/operation-id"

PowerShell

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/locations/location-id/operations/operation-id" | Select-Object -Expand Content
完成商品集完全清除操作后,您应会看到如下所示的输出:
{
  "name": "locations/location-id/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata",
    "state": "SUCCESSFUL",
    "submitTime": "2019-09-04T15:58:39.131591882Z",
    "endTime": "2019-09-04T15:58:43.099020580Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest",
    "parent": "projects/project-id/locations/location-id",
    "productSetPurgeConfig": {
      "productSetId": "project-set-id"
    },
    "force": true
  }
}

完成孤立的商品完全清除操作后,您应会看到如下所示的输出:

{
  "name": "locations/location-id/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata",
    "state": "SUCCESSFUL",
    "submitTime": "2019-09-04T16:08:38.278197397Z",
    "endTime": "2019-09-04T16:08:45.075778639Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest",
    "parent": "projects/project-id/locations/location-id",
    "deleteOrphanProducts": true,
    "force": true
  }
}