gpt4 book ai didi

node.js - Dialog api v2 - 获取应用程序默认凭据时出现意外错误 : Could not load the default credentials

转载 作者:太空宇宙 更新时间:2023-11-03 22:59:55 25 4
gpt4 key购买 nike

我正在尝试使用谷歌对话流实现聊天机器人应用程序。我正在学习这个 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.

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

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

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

最佳答案

根据这个linkgithub repo here您应该能够在 const sessionClient 中设置凭据:

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

关于node.js - Dialog api v2 - 获取应用程序默认凭据时出现意外错误 : Could not load the default credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50851727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com