问题描述
在Google Cloud vision API documentation中,用于产品搜索的获取操作状态的方法列为CMD,但没有C#代码示例可以用来检查任何长期运行的操作状态。
我尝试在邮递员中调用此方法,但由于无法添加服务帐户凭据而无法使用
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
-
使用带有stringify的AJAX向服务帐户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));