如何解决通过API而不是CMD获取操作状态
在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));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。