【问题标题】:Dialog api v2 - Unexpected error while acquiring application default credentials: Could not load the default credentialsDialog api v2 - 获取应用程序默认凭据时出现意外错误:无法加载默认凭据
【发布时间】:2018-11-23 21:23:36
【问题描述】:

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

但这样做也无济于事。有没有办法从代码中手动提供这个密钥文件,而不是设置环境变量。

【问题讨论】:

    标签: node.js nlp google-cloud-platform dialogflow-es service-accounts


    【解决方案1】:

    根据linkgithub repo here,您应该可以在const sessionClient 中设置凭据:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 2012-01-25
      • 2021-01-06
      • 2020-04-28
      相关资源
      最近更新 更多