With version 1 this is how I used to communicate with DialogFlow Api!
fetch(configs.baseUrl + \"query?v=20150910\", {
body: JSON.stringify({query: text,
Below is another example of creating your DialogFlow V2 access token using Node.js. The library that is used in the code below is google-oauth-jwt.
const googleAuth = require('google-oauth-jwt');
function generateAccessToken() {
return new Promise((resolve) => {
googleAuth.authenticate(
{
email: <client_email>,
key: <private_key>,
scopes: 'https://www.googleapis.com/auth/cloud-platform',
},
(err, token) => {
resolve(token);
},
);
});
}
You may find your client_email
and private_key
from the JSON key file you have downloaded from your Google Cloud Platform project's service account page. If you are unsure how/where to download it, you may checkout my blog post here.
To find out which scope which scope you may need, you may checkout the DialogFlow V2 REST API documentation page.
You might be interested in this:
https://cloud.google.com/docs/authentication/api-keys
You did pretty much the right thing, but you would probably want to use Dialogflows Node.js client SDK. These SDKs read the authentication JSON file automatically when you instantiate a client (see the example on Github, the file is read by ... = new dialogflow.SessionsClient()
).