我有一个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
的来源,因为当我单击链接时,它不是有效的项目
第二,我选择了项目并在其上启用了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"
},
我找到了我项目的projectId,该ID与错误消息中的ID不同
我检查了我拥有的所有其他项目的ID,该数字与任何项目都不匹配
该问题仅在我的本地上发生,当部署到Firebase时有效
导出服务密钥文件
GOOGLE_APPLICATION_CREDENTIALS
的环境变量(win 10)