简体   繁体   中英

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

i am trying to implement a chat bot application with google dialog flow. i was fallowing this github tutorial https://github.com/dialogflow/dialogflow-nodejs-client-v2 to implement api. this is my code

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;

once i start my application i am getting the bellow error

(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.

so i tried to figure out the issue and found that i need to Set up authentication with a service account. and i did that downloaded the key file that contain required keys and ran the command

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

but doing this also did nothing. is there a way to manually provide this key file from the code instead of setting an environment variable.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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