[英]PermissionError using google cloud Vision Api in Firebase Functions in nodejs
I have a firebase function and I tried to use Vision API in my firebase function, but I get this error when serve locally I have a firebase function and I tried to use Vision API in my firebase function, but I get this error when serve locally
PERMISSION_DENIED: Cloud Vision API has not been used in project 563584335869 before or it is disabled. PERMISSION_DENIED:Cloud Vision API 之前未在项目 563584335869 中使用或已禁用。 Enable it by visiting https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=563584335869 then retry.通过访问https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=563584335869启用它,然后重试。 If you enabled this API recently如果你最近启用了这个 API
First of all, I don't know where 563584335869
comes from, since when I click on the link it's not a valid project首先,我不知道563584335869
来自哪里,因为当我点击链接时它不是一个有效的项目
Second, I select the project and enabled Vision API on it, still getting same error其次,我 select 项目并在其上启用了 Vision API,仍然得到同样的错误
the code is very straight forward, anyway I add it here代码很简单,反正我在这里添加
async analyze(imageStorageLocation: string): Promise<any> {
const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
const [result] = await client.textDetection(imageStorageLocation);
const detections = result.textAnnotations;
console.log('Text:');
detections.forEach((text: string) => console.log(text));
}
ange this is how I initialized firebase admin admin.initializeApp(functions.config().firebase);
我就是这样初始化 firebase admin admin.initializeApp(functions.config().firebase);
and here is the package.json
这是package.json
"dependencies": {
"@google-cloud/vision": "^1.7.1",
"@nestjs/common": "^6.0.0",
"@nestjs/core": "^6.0.0",
"@nestjs/platform-express": "^6.9.0",
"express": "^4.17.1",
"firebase-admin": "^8.7.0",
"firebase-functions": "^3.3.0",
"moment-timezone": "^0.5.27",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3"
},
This is how google cloud dashboard looks like这就是谷歌云仪表板的样子
I found projectId of my project, which is different than the id in the error message我发现我的项目的 projectId 与错误消息中的 id 不同
I checked id of all other projects that I have, the number doesn't match to any我检查了我拥有的所有其他项目的 ID,该数字与任何项目都不匹配
The issue only happens on my local, when deployed to firebase it works该问题仅发生在我的本地,当部署到 firebase 时它可以工作
Thanks @Chris32, I found the solution based on his lead in the comments.谢谢@Chris32,我根据他在评论中的引导找到了解决方案。
Since the issue was only on my local serve and it was OK on deployment I did this to solve the issue ( https://cloud.google.com/vision/docs/before-you-begin )由于问题仅在我的本地服务器上并且在部署时没问题,我这样做是为了解决问题( https://cloud.google.com/vision/docs/before-you-begin )
GOOGLE_APPLICATION_CREDENTIALS
创建一个名为GOOGLE_APPLICATION_CREDENTIALS
的环境变量(win 10)ps Surprisingly as Chris mentioned the project id in the error is hard coded and so misleading ps 令人惊讶的是,克里斯提到错误中的项目 id 是硬编码的,因此具有误导性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.