長期執行的作業
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
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
3326639765503758657
- 注意:
- PROJECT_NUMBER:您的 GCP 專案 ID
- LOCATION_ID:應進行註解的雲端區域。支援的雲端區域包括:
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) 和空白回應。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-09 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-09 (世界標準時間)。"],[],[]]