Nodejs-dialogflow: Dialogflow API has not been used in project usable-auth-library before or it is disabled.

Created on 20 Apr 2018  路  23Comments  路  Source: googleapis/nodejs-dialogflow

MAC Osx High Sierra
Node v9.11.1
npm 5.6.1
dialog flow 0.3.0

const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
const request = {
session: sessionPath,
queryInput: {
text: {
text: text,
languageCode: lang,
},
},
};
try {
let responses = await sessionClient.detectIntent(request);
} catch (err) {
return console.error('ERROR:', err);
}

Error: 7 PERMISSION_DENIED: Dialogflow API has not been used in project usable-auth-library before or it is disabled. Enable it

triage me dialogflow

Most helpful comment

Solution of @lukaszbk solved my problem.
I use IDEA in Ubuntu, in terminal window type in:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

All 23 comments

@ViswanathLekshmanan Have yo enabled it? GO to your GCP console and enable this api before trying.

@axchanda yes it is already enabled.

@ViswanathLekshmanan Have you solved it? I am getting the same error.
I did every thing as stated in _https://dialogflow.com/docs/reference/v2-auth-setup_
I was stuck with this error

(node:9624) UnhandledPromiseRejectionWarning: 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.
    at GoogleAuth.<anonymous>

Then I resolved it with gcloud auth application-default login
Now i am getting
Error: 7 PERMISSION_DENIED: Dialogflow API has not been used in project usable-auth-library before or it is disabled. Enable it

@sarathi0333 I havent solved it. I started using REST API v1 from dialogflow.

@ViswanathLekshmanan But they made V2 as default and any new update will be only to v2... I will try to find out. If i could will let you.
If you found also let me know

@sarathi0333 sure.

@ViswanathLekshmanan I was having a similar error; to resolve you have to go into https://console.cloud.google.com/ and check the IAM user permissions on the user account for your compute instance. (it may be something like @appspot...)
Make sure that user has all three permissions for DialogFlow

Judging by the error you are getting, credentials are not set up correctly in your environment. Please follow:

Solution of @lukaszbk solved my problem.
I use IDEA in Ubuntu, in terminal window type in:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

Using Node.js.
Exporting the GOOGLE_APPLICATION_CREDENTIALS env var as written by @bruceyo solved my problem. I think it should be in written in the documentation.

Could not load the default credentials

where the f**k do you need credentials? the example code you have provided is not working with v2 at all

@lukaszbk why did you closed the issue? do you have any solution for this issue? my server is running on heroku and I want to call dialogflow from heroku server

@malikasinger1 if you don't want to supply credentials explicitly, you can set them in an environment variable called GOOGLE_APPLICATION_CREDENTIALS. You can read more about how to generate/configure them, etc. in the authentication getting started guide

@callmehiphop I wanted to provide the credentials explicitly but I don't know how to do that, you never explained this in the documents, may be you have explained but I didn't found it, please share how to do that

I understand I can set environment variable named GOOGLE_APPLICATION_CREDENTIALS with value /path/to/service-account-file.json, but i wanted to do something i can do in dialogflow v1 client library, please share example code, I am lazy to read longs texts but I understand code quickly

do you even realized Mr. @ViswanathLekshmanan who originally asked this question have moved back to v1 since you don't have a proper solution for his problem, it is called failure in my opinion, I am also going to do that if you the writers f this library will not help me or i will write my own library on the top of dialogflow v2 REST apis

@malikasinger1 you have a couple of options when it comes to authenticating, I think all of the options are documented in each class constructor (e.g. v2.SessionsClient).

If you don't want to use the env var, the next easiest option to just supply a path to the credentials

const dialogflow = require('dialogflow');

const client = new dialogflow.v2.SessionsClient({
  keyFilename: '/path/to/keyfile.json'
});

@callmehiphop can you please list down how many version of documents do you, please list down here

@malikasinger1 I'm not sure I understand what you are asking for, do you mean dialogflow versions? If so, the client only ships with v2beta1 and v2.

and @callmehiphop do you realized may be they have incorrect code in your repository sample code

this is the code you do have as try an example:

  ...

  // Send request and log result
  const responses = await sessionClient.detectIntent(request);
  console.log('Detected intent');
  const result = responses[0].queryResult;
  console.log(`  Query: ${result.queryText}`);
  console.log(`  Response: ${result.fulfillmentText}`);
  if (result.intent) {
    console.log(`  Intent: ${result.intent.displayName}`);
  } else {
    console.log(`  No intent matched.`);
  }

  ...

and in fact result.fulfillmentText does not exist, it is giving me undefined

that much effort I have done(see console.logs below) just to understand that instead of responses[0].queryResult.fulfillmentText now they return responses[0].queryResult.fulfillmentMessages and it is not a text string but it is an object which have further values in it that you can see in console.logs below:

...

// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');

console.log("responses: ", responses)
console.log("responses[0]: ", responses[0])
console.log("responses[0].queryResult: ", responses[0].queryResult)
console.log("responses[0].queryResult.fulfillmentMessages: ", responses[0].queryResult.fulfillmentMessages)
// console.log("responses[0].queryResult.fulfillmentMessages[1]: ", responses[0].queryResult.fulfillmentMessages[1])
console.log("responses[0].queryResult.fulfillmentMessages[0]: ", responses[0].queryResult.fulfillmentMessages[0])
console.log("responses[0].queryResult.fulfillmentMessages[0].text: ", responses[0].queryResult.fulfillmentMessages[0].text)
console.log("responses[0].queryResult.fulfillmentMessages[0].text.text: ", responses[0].queryResult.fulfillmentMessages[0].text.text)
console.log("responses[0].queryResult.fulfillmentMessages[0].text.text[0]: ", responses[0].queryResult.fulfillmentMessages[0].text.text[0])

var fulfilmentText = responses[0].queryResult.fulfillmentMessages[0].text.text[0]

 ...

peak of irresponsibility yo, I am done with you guys

@malikasinger1 I totally agree we could be doing a better job of documenting our client libraries, I think you'll be pleased to know that an effort to do just that is already underway.

result.fulfillmentText does not exist, it is giving me undefined

According to the upstream docs both fulfillmentText and fulfillmentMessages can exist on a single response, but it does also say it is a legacy field.

@nnegrey any idea why fulfullmentText might come back undefined?

Was this page helpful?
0 / 5 - 0 ratings