您可以删除 API 创建的参考图片、商品或商品集资源。
删除单个资源
删除参考图片
您可以删除与商品关联的参考图片。
执行操作请求后,图片会标记为删除,但在下次编制索引之前仍保留在商品中。
此操作不会删除 Cloud Storage 中的实际图片文件。而是仅从商品中移除了对图片的引用。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - PRODUCT_ID:与参考图片关联的商品的 ID。此 ID 由用户在创建商品时随机设置或指定。
- IMAGE_ID:目标图片资源的 ID。
HTTP 方法和网址:
DELETE https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id/referenceImages/image-id
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id/referenceImages/image-id"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id/referenceImages/image-id" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{}
Go
Java
Node.js
Python
其他语言
C#: 请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Vision API Product Search 参考文档。
PHP: 请按照客户端库页面上的 PHP 设置说明操作,然后访问 PHP 版 Vision API Product Search 参考文档。
Ruby 版: 请按照客户端库页面上的 Ruby 设置说明操作,然后访问 Ruby 版 Vision API Product Search 参考文档。
删除商品
您可以删除与特定项目关联的商品。
删除某一产品后,其子图片也会随之删除。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - PRODUCT_ID:与参考图片关联的商品的 ID。此 ID 由用户在创建商品时随机设置或指定。
HTTP 方法和网址:
DELETE https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{}
Go
Java
Node.js
Python
其他语言
C#: 请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Vision API Product Search 参考文档。
PHP: 请按照客户端库页面上的 PHP 设置说明操作,然后访问 PHP 版 Vision API Product Search 参考文档。
Ruby 版: 请按照客户端库页面上的 Ruby 设置说明操作,然后访问 Ruby 版 Vision API Product Search 参考文档。
删除商品集
您还可以删除商品集。
删除某一商品集后,该商品集会立即从结果中移除。 但是,删除某一商品集不会移除该商品集中的个别商品,因为一个商品可能属于多个不同的商品集。此更改无需等到下次索引即会生效。
此操作不会删除 Cloud Storage 中的实际图片文件。API 创建的 ReferenceImage
资源不会被移除。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - PRODUCT_SET_ID:您要对其执行操作的商品集的 ID。
HTTP 方法和网址:
DELETE https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets/product-set-id
如需发送请求,请选择以下方式之一:
curl
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets/product-set-id"
PowerShell
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets/product-set-id" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{}
Go
Java
Node.js
Python
其他语言
C#: 请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Vision API Product Search 参考文档。
PHP: 请按照客户端库页面上的 PHP 设置说明操作,然后访问 PHP 版 Vision API Product Search 参考文档。
Ruby 版: 请按照客户端库页面上的 Ruby 设置说明操作,然后访问 Ruby 版 Vision API Product Search 参考文档。
批量删除资源
您现在可以批量删除商品。批量删除商品的操作适用于以下商品类型:
- 特定商品集中的所有商品
- 不属于任何商品集的所有商品
为了避免出现并发操作错误,请等待此批量商品删除操作完成后再删除商品集。如果要重复使用清空的商品集,也要等到批量删除操作完成后再导入新商品。
对于单个商品而言,这些注意事项是相似的;您应该避免对批量删除操作涉及的任何单个商品执行操作。例如,您不应将这些商品中的任何商品添加到其他商品集中,因为它们最终会被删除。
删除商品集中的商品
您可以通过在请求中指定商品集 ID 来删除给定商品集中的所有商品。
系统会删除该商品集中的所有商品,无论它们是否属于其他商品集都是如此。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - PRODUCT_SET_ID:您要对其执行操作的商品集的 ID。
HTTP 方法和网址:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products:purge
请求 JSON 正文:
{ "force": "true", "productSetPurgeConfig": { "productSetId": "product-set-id" } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products:purge"
PowerShell
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products:purge" | Select-Object -Expand Content
此请求会启动长时间运行的操作。JSON 响应包含有关此长时间运行操作的信息:
{ "name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626" }
在本示例中,operation-id 为 bc4e1d412863e626
。
您可以使用 operation-id 跟踪此操作的进度。 如需查看获取操作状态的示例,请参阅获取操作状态。
Go
Java
Node.js
Python
其他语言
C#: 请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Vision API Product Search 参考文档。
PHP: 请按照客户端库页面上的 PHP 设置说明操作,然后访问 PHP 版 Vision API Product Search 参考文档。
Ruby 版: 请按照客户端库页面上的 Ruby 设置说明操作,然后访问 Ruby 版 Vision API Product Search 参考文档。
删除孤立商品
通过在请求中指定此选项,您可以删除不在商品集中的所有商品。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。
HTTP 方法和网址:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products:purge
请求 JSON 正文:
{ "force": "true", "deleteOrphanProducts": "true" }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products:purge"
PowerShell
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products:purge" | Select-Object -Expand Content
此请求会启动长时间运行的操作。JSON 响应包含有关此长时间运行操作的信息:
{ "name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626" }
在本示例中,operation-id 为 bc4e1d412863e626
。
您可以使用 operation-id 跟踪此操作的进度。 如需查看获取操作状态的示例,请参阅获取操作状态。
Go
Java
Node.js
Python
其他语言
C#: 请按照客户端库页面上的 C# 设置说明操作,然后访问 .NET 版 Vision API Product Search 参考文档。
PHP: 请按照客户端库页面上的 PHP 设置说明操作,然后访问 PHP 版 Vision API Product Search 参考文档。
Ruby 版: 请按照客户端库页面上的 Ruby 设置说明操作,然后访问 Ruby 版 Vision API Product Search 参考文档。
获取操作状态
您可以使用长时间运行的操作(如完全清除商品集或完全清除孤立商品)的 operation-id 来获取其状态。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_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 } }