我的代码如下:-
var vision = require('@google-cloud/vision');
handleSubmit = () =>{
console.log("encoded string submitted=",this.state.files);
this.useVisionCloud();
}
useVisionCloud = () =>{
const client = new vision.ImageAnnotatorClient();
const request_body = {
"requests": [
{
"image": {
"content": this.state.files
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
};
client.textDetection(request_body).then(response => {
console.log("text got=",response);
// doThingsWith(response);
})
.catch(err => {
console.log("error got=",err);
});
}
我收到以下错误:-
Uncaught Error: {"clientConfig":{},"port":443,"servicePath":"vision.googleapis.com","scopes":["https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloud-vision"]}You need to pass auth instance to use gRPC-fallback client in browser. Use OAuth2Client from google-auth-library.
触发对Google API的发布请求。
最终查询是:-我无法理解如何对API进行身份验证,以便我可以进一步使用它来检测图像中的文本
答案 0 :(得分:0)
设置环境变量,例如: 导出GOOGLE_APPLICATION_CREDENTIALS =“ [PATH]”
我建议您使用一个单独的后端,该后端称为vision api。然后让浏览器中的javascript代码调用您的后端。