[nodejs的Firebase函数中使用Google Cloud Vision Api的PermissionError

问题描述 投票:1回答:1

我有一个firebase函数,我尝试在我的firebase函数中使用Vision API,但是在本地提供服务时出现此错误

PERMISSION_DENIED:在项目563584335869中尚未使用Cloud Vision API或将其禁用。通过访问https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=563584335869启用它,然后重试。如果您最近启用了此API

首先,我不知道563584335869的来源,因为当我单击链接时,它不是有效的项目enter image description here

第二,我选择了项目并在其上启用了Vision API,仍然出现相同的错误

代码非常简单,无论如何我都在这里添加它

    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,这是我初始化firebase管理员的方式admin.initializeApp(functions.config().firebase);

这里是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"
  },

更新

这是Google云信息中心的外观enter image description here

更新

我找到了我项目的projectId,该ID与错误消息中的ID不同enter image description here

更新

我检查了我拥有的所有其他项目的ID,该数字与任何项目都不匹配

更新

该问题仅在我的本地上发生,当部署到Firebase时有效

firebase google-cloud-platform google-cloud-functions google-vision
1个回答
1
投票
由于该问题仅在我的本地服务器上,并且在部署时还可以,所以我这样做是为了解决问题(https://cloud.google.com/vision/docs/before-you-begin

导出服务密钥文件

    创建一个名为GOOGLE_APPLICATION_CREDENTIALS的环境变量(win 10)
  1. 将服务密钥文件的路径设置为此env变量
  2. 本地运行功能
  • ps令人惊讶的是,克里斯提到错误中的项目ID是硬编码的,因此具有误导性
  • © www.soinside.com 2019 - 2024. All rights reserved.