title: Can't access correct application default credentials for Dialogflow app
body: <p>I have created a Dialogflow agent with a concurrent gcloud app. However, when I try to integrate it into a Node.js backend, it seems to be accessing the wrong application default credentials.</p>
  
  <p>I can confirm that it is verifying authentication is successful because it console logs the correct project ID (diagnosistest-56e81) when I run this code:</p>
  
  <pre><code>// Imports the Google Cloud client library.
  const Storage = require('@google-cloud/storage')
  
  // Instantiates a client. If you don't specify credentials when constructing
  // the client, the client library will look for credentials in the
  // environment.
  const storage = new Storage();
  
  // Makes an authenticated API request.
  storage
    .getBuckets()
    .then((results) =&gt; {
      const buckets = results[0];
  
      console.log('Buckets:');
      buckets.forEach((bucket) =&gt; {
        console.log(bucket.name);
      });
    })
    .catch((err) =&gt; {
      console.error('ERROR:', err);
    })
  </code></pre>
  
  <p>However, when I try to connect dialogflow, I get an error.</p>
  
  <p>Code to connect to dialogflow:</p>
  
  <pre><code>// You can find your project ID in your Dialogflow agent settings
  const projectId = 'diagnosistest-56e81'; //https://dialogflow.com/docs/agents#settings
  const sessionId = 'quickstart-session-id';
  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);
  
  // The text query request.
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: query,
        languageCode: languageCode,
      },
    },
  };
  
  // Send request and log result
  sessionClient
    .detectIntent(request)
    .then(responses =&gt; {
      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.`);
      }
    })
    .catch(err =&gt; {
      console.error('ERROR:', err);
    });
  </code></pre>
  
  <p>Error message that I receive:</p>
  
  <pre><code>ERROR: { Error: 7 PERMISSION_DENIED: Dialogflow API has not been used in project 764086051850 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/dialogflow.googleapis.com/overview?project=764086051850 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
  </code></pre>
  
  <p>The weird thing is, my project number is 889800549397 and not 764086051850. So it seems like it's not accessing the correct credentials.</p>
  
  <p><strong>What I've tried so far:</strong></p>
  
  <ol>
  <li>Create new Dialogflow service account key and setting export to the json key file via <code>export GOOGLE_APPLICATION_CREDENTIALS='/Users/Joseph/workspace/finddoc/DiagnosisTest-cred.json</code></li>
  <li>Deleting <code>application_default_credentials.json</code> file in <code>./config/gcloud/</code> folder. </li>
  </ol>
  
  <p>When I do this I get a different error message:</p>
  
  <pre><code>ERROR: 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.
  </code></pre>