繁体   English   中英

Dialog api v2 - 获取应用程序默认凭据时出现意外错误:无法加载默认凭据

[英]Dialog api v2 - Unexpected error while acquiring application default credentials: Could not load the default credentials

我正在尝试使用谷歌对话框流程实现聊天机器人应用程序。 我正在暂停这个github教程https://github.com/dialogflow/dialogflow-nodejs-client-v2来实现api。 这是我的代码

var express = require('express');
var router = express.Router();
const projectId = 'my-project-id'; //https://dialogflow.com/docs/agents#settings
const sessionId = 'random no';
const query = 'hello';
const languageCode = 'en-US';
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();

// // Define session path
// const sessionPath = sessionClient.sessionPath(projectId, sessionId);
/* GET home page. */
router.get('/', function(req, res, next) {


});

module.exports = router;

一旦我开始我的应用程序,我收到波纹管错误

(node:6436) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
(node:6436) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.

所以我试图找出问题,发现我需要使用服务帐户设置身份验证。 我这样做下载了包含所需密钥的密钥文件并运行命令

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

但这样做也没有做任何事情。 有没有办法从代码手动提供此密钥文件,而不是设置环境变量。

根据此链接github repo,您应该能够在const sessionClient设置凭据:

const sessionClient = new dialogflow.SessionsClient({ keyFilename: "relative/path/to/key.json" })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM