簡體   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