当我尝试使用云视觉API运行firebase功能并测试功能时。我收到此错误:
错误:{错误:7 PERMISSION_DENIED:Cloud Vision API之前尚未在项目563584335869中使用或被禁用。通过访问https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=563584335869启用它,然后重试。如果您最近启用了此API,请等待几分钟,以便将操作传播到我们的系统并重试。
我不认识这个项目编号,我已经使用我正在使用的项目启用了API。我使用启用了API的项目设置了GOOGLE_APPLICATION_CREDENTIALS
。我做错了什么?
由于多种原因(例如丢失文件,无效的凭据路径,不正确的环境变量分配等原因),当应用程序未正确进行身份验证时,通常会抛出此错误消息。
基于此,我建议您验证是否正确分配了凭据文件和文件路径,并遵循Obtaining and providing service account credentials manually指南,以便直接在您的代码中明确指定您的服务帐户文件;通过这种方式,您将能够永久地设置它并验证您是否正确传递服务凭据。此外,您还可以查看this link,其中包含使用Vision API的Firebase功能的有用分步指南,其中包括Node.js的Vision对象身份验证代码。
在代码示例中将路径传递给服务帐户密钥:
// Imports the Google Cloud client library.
const Storage = require('@google-cloud/storage');
// Instantiates a client. Explicitly use service account credentials by
// specifying the private key file. All clients in google-cloud-node have this
// helper, see https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/docs/authentication.md
const storage = new Storage({
keyFilename: '/path/to/keyfile.json'
});
// Makes an authenticated API request.
storage
.getBuckets()
.then((results) => {
const buckets = results[0];
console.log('Buckets:');
buckets.forEach((bucket) => {
console.log(bucket.name);
});
})
.catch((err) => {
console.error('ERROR:', err);
});