node.js - 如何使用客户端库连接到 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 教程,所以我不确定为什么这不起作用。我错过了身份验证的步骤吗?
解决方案
推荐阅读
- php - PHP:使用一个数组中的单个值作为另一个数组的键?
- r - 如何使用 R 根据 A 列中的值组合 B 列中的值?
- ruby - 通过 ruby 的 github api 问题
- json - 如何在 OpenAPI 中指定多文件上传?
- static - 如何使用从 Python 派生的变量在 C 中具有可变的静态数组大小
- python-3.x - 图例和 x 标签问题
- java - Apache Camel,在@DataField bindy 中将字符串转换为整数
- arrays - 将 PowerShell 中的数组与文件目录进行比较 效率低下
- c# - 如何将数组中的所有内容向上移动一个位置?C#
- node.js - Node.js 从文本文档中阅读每日提示