我有一个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));
}
这是我初始化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时有效