您要求的多項作業都是長時間執行的作業,例如透過大量匯入建立產品組合、清除產品組合,以及清除孤立產品。這類要求會傳回 JSON,其中包含作業 ID,可用於取得作業狀態。
舉例來說,批次刪除 (purge
) 要求會傳回下列 JSON:
{ "name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626" }
在本例中,作業 ID 為 bc4e1d412863e626
。下列範例說明如何使用這個 ID 取得這項作業的狀態。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的 Google Cloud 專案 ID。
- LOCATION_ID:有效的地點 ID。有效的位置識別碼包括:
us-west1
、us-east1
、europe-west1
和asia-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 } }