首页 > 解决方案 > 如何使用客户端库连接到 Google Vision?(Node.js)

问题描述

我正在尝试按照本教程使用 Node.js 将图像发送到 Google Vision API:https ://cloud.google.com/vision/docs/libraries

我已经安装了客户端库。然后,我创建了一个服务帐户密钥,并将 GOOGLE_APPLICATION_CREDENTIALS 环境变量的值显式设置为在创建服务帐户密钥时下载的 JSON 文件。

但是,当我运行以下 Node.js 代码时:

// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');

// Creates a client
const client = new vision.ImageAnnotatorClient();

// Performs label detection on the image file
client
  .labelDetection('./Driver_license.jpg')
  .then(results => {
    const labels = results[0].labelAnnotations;

    console.log('Labels:');
    labels.forEach(label => console.log(label.description));
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

我在控制台中收到以下 2 个错误:

(node:22585) DeprecationWarning: grpc.load: 将@grpc/proto-loader 模块与 grpc.loadPackageDefinition 一起使用

身份验证错误:错误:证书链中的自签名证书

关于 Auth 错误的第二个错误继续一遍又一遍地打印出来,直到我终止执行。

我已经密切关注 Google Cloud 教程,所以我不确定为什么这不起作用。我错过了身份验证的步骤吗?

标签: node.jsauthenticationgoogle-cloud-platformgcloudgoogle-vision

解决方案


推荐阅读