azure - Google Cloud Vision 反向图像搜索在 Azure 应用服务上失败,因为找不到 GOOGLE_APPLICATION_CREDENTIALS 文件

标签 azure google-api azure-web-app-service google-cloud-vision azure-app-service-plans

我正在尝试使用 Google Cloud Vision 执行 Google 反向图像搜索在 Azure 应用服务 Web 应用上。

我已经生成了 googleCred.json,Google 客户端库使用它来构造 API 请求。 Google 希望可以通过名为 GOOGLE_APPLICATION_CREDENTIALS 的环境变量来使用它。

运行 Web 应用的 Azure 应用服务具有模仿 Google 客户端库的环境变量的设置。文档是here ,我已经在这里成功设置了变量:

enter image description here

此外,googleCred.json 文件已上传到应用服务。这是documentation我接着使用FTP和FileZilla上传文件:

enter image description here

此外,文件权限尽可能开放:

enter image description here

但是,当我访问云端的 Web 应用程序时,收到以下错误消息:

Error reading credential file from location D:\site\wwwroot\Statics\googleCred.json: Could not find a part of the path 'D:\site\wwwroot\Statics\googleCred.json'. Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS

我做错了什么?如何在 Azure Web 应用上成功使用 Google Cloud Vision API?

最佳答案

当应用程序由于文件丢失、凭据路径无效、环境变量分配不正确等多种原因而无法正确身份验证时,通常会抛出此错误消息。

基于此,我建议您验证凭证文件和文件路径是否已正确分配,并遵循 Obtaining and providing service account credentials manually指导以便直接在代码中明确指定您的服务帐户文件;通过这种方式,您将能够永久设置它并验证您是否正确传递了服务凭据。

在代码示例中传递服务帐户 key 的路径:

// 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);
  });

关于azure - Google Cloud Vision 反向图像搜索在 Azure 应用服务上失败,因为找不到 GOOGLE_APPLICATION_CREDENTIALS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52186137/

相关文章:

azure - 复制文件上传过程 - Asp.net WebApi

c# - purchase.products.get 忽略 productId 值并在 ProductPurchase 中返回 null

azure - Azure 网站的最大横向扩展

azure - Visual Studio 2022 发布窗口未检测身份验证状态

Azure 应用程序洞察

c# - 手动重新启动 Azure Worker 角色 "WaWorkerHost.exe"

asp.net - 是否可以将 Azure 连接到 google 云端硬盘?

javascript - 谷歌图表减少增加点

javascript - 带有图例和其他颜色的 Google Charts API 散点图

c# - "Could not find a part of the path"Azure应用程序中文件读取操作错误