通过 API 而非 CMD 获取操作状态
GET operation status via API not CMD
在GoogleCloud vision API documentation产品搜索中,获取操作状态的方法列为CMD,但没有C#代码示例,以便检查任何long-运行 运行状态.
我尝试在 postman 中调用此方法,但它不起作用,因为我无法添加服务帐户凭据
GET https://vision.googleapis.com/v1/locations/location-id/operations/operation-id
非常感谢对此的任何指导。
原来有两种解法:
- 使用 Google Cloud Vision REST APIKEY 作为查询参数(您必须从云控制台凭据生成自己的 API 密钥)
GET https://vision.googleapis.com/v1/locations/location_id/operations/operation_id?key=value
使用 AJAX 和 stringify 将服务帐户 JSON 密钥文件附加到发送到上面相同 URL 的请求。
checkStatus: function() {
if (this.get('stop') || !this.getOperationUrl()) {
return;
}
$.ajax({
url: '/getOperation',
type: 'POST',
data: JSON.stringify({
operation_url: this.getOperationUrl(),
key: this.config_model.get('key'),
}),
cache: false,
contentType: 'application/json',
dataType: 'json',
}).done(function(response) {
const result = response.response;
if (!response.success || !result) {
console.log(response);
this.set('response', response);
} else {
if (result.done) {
this.set('response', response);
} else {
setTimeout(function() {
this.checkStatus();
}.bind(this), 5 * 1000);
}
}
}.bind(this));
在GoogleCloud vision API documentation产品搜索中,获取操作状态的方法列为CMD,但没有C#代码示例,以便检查任何long-运行 运行状态.
我尝试在 postman 中调用此方法,但它不起作用,因为我无法添加服务帐户凭据
GET https://vision.googleapis.com/v1/locations/location-id/operations/operation-id
非常感谢对此的任何指导。
原来有两种解法:
- 使用 Google Cloud Vision REST APIKEY 作为查询参数(您必须从云控制台凭据生成自己的 API 密钥)
GET https://vision.googleapis.com/v1/locations/location_id/operations/operation_id?key=value
使用 AJAX 和 stringify 将服务帐户 JSON 密钥文件附加到发送到上面相同 URL 的请求。
checkStatus: function() { if (this.get('stop') || !this.getOperationUrl()) { return; } $.ajax({ url: '/getOperation', type: 'POST', data: JSON.stringify({ operation_url: this.getOperationUrl(), key: this.config_model.get('key'), }), cache: false, contentType: 'application/json', dataType: 'json', }).done(function(response) { const result = response.response; if (!response.success || !result) { console.log(response); this.set('response', response); } else { if (result.done) { this.set('response', response); } else { setTimeout(function() { this.checkStatus(); }.bind(this), 5 * 1000); } } }.bind(this));