简体   繁体   English

PermissionError 使用谷歌云视觉 Api in Firebase Functions in nodejs

[英]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"
  },

Update更新

This is how google cloud dashboard looks like这就是谷歌云仪表板的样子在此处输入图像描述

Update更新

I found projectId of my project, which is different than the id in the error message我发现我的项目的 projectId 与错误消息中的 id 不同在此处输入图像描述

Update更新

I checked id of all other projects that I have, the number doesn't match to any我检查了我拥有的所有其他项目的 ID,该数字与任何项目都不匹配

Update更新

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

  1. exported a service key file导出服务密钥文件
  2. create a environment variable (win 10) named GOOGLE_APPLICATION_CREDENTIALS创建一个名为GOOGLE_APPLICATION_CREDENTIALS的环境变量(win 10)
  3. set the path of service key file to this env variable将服务密钥文件的路径设置为此环境变量
  4. run functions locally在本地运行函数

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.

相关问题 在Firebase Cloud Functions中使用Google Vision API时发生TypeError - TypeError when using Google Vision API in Firebase Cloud Functions 使用Google People API和Firebase的云功能 - Using Google People API with Cloud Functions for Firebase Firebase Ml 套件、Google 云视觉 API 或 openCV - Firebase Ml kit, Google cloud vision API or openCV 如何将Firebase存储图像与Google Cloud Vision API一起使用? - How to use Firebase Storage image with Google Cloud Vision API? 无法使用 NodeJS(Google 云功能)在 firebase firestore 中获取文档 ID - Unable to fetch docs ids in firebase firestore using NodeJS (Google cloud functions) 使用Firebase在Google Cloud Functions上部署时,Cloud Storage API不起作用 - Cloud Storage API doesn't work when deploy on Google Cloud Functions using Firebase 使用Firebase / Google Cloud功能推送通知 - Push Notifications using Firebase/Google Cloud Functions Firebase:为您的 Cloud Functions 项目启用 Google Cloud Build API? - Firebase: Enable the Google Cloud Build API for your Cloud Functions project? 使用 Axios 和 Firebase 云函数调用 API - Calling an API using Axios and Firebase Cloud Functions 如何使用 API 存储在 Google 中的密钥 Firebase 云函数 - How to use API Keys stored in Google Firebase Cloud Functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM