title: Why my API calls using google-api-nodejs-client to Google Analytics are not working in production?
body: <p>I'm calling the <a href="https://developers.google.com/analytics/devguides/reporting/core/v4/?hl=pt-br" rel="nofollow noreferrer">Google Analytics Reporting API</a> using <a href="https://github.com/googleapis/google-api-nodejs-client" rel="nofollow noreferrer">google-api-nodejs-client</a> to show the number of visits inside a blog.</p>
  
  <p>This blog is hosted inside Google App Engine Standard Environment.</p>
  
  <p>In development, I'm authenticating my API calls using the <a href="https://cloud.google.com/docs/authentication/production" rel="nofollow noreferrer">Application Default Credentials</a>. I downloaded the JSON file with the credentials from the account service I created exclusively for analytics purposes, set the file to the Google_Application_Credentials environment variable and everything worked. I'm able to get the data from Google Analytics and display it in the website.</p>
  
  <p>But this is not working in production. I suppose <code>getClient()</code> it's not getting the credentials in that environment.</p>
  
  <p>Things to note: 1) I did not upload the downloaded JSON file with the credentials from the service account (I think it would be counter intuitive and unsafe to do that, and from what I understood in the docs, GCP is able to deal automatically with the API authentications); </p>
  
  <pre><code>
  const {google} = require("googleapis");
  
  async function main () {
  
      // This method looks for the GCLOUD_PROJECT and GOOGLE_APPLICATION_CREDENTIALS
      // environment variables.
      const auth = await google.auth.getClient({
          // Scope of the analytics reporting,
          // with only reading access.
          scopes: 'https://www.googleapis.com/auth/analytics.readonly',
      });
  
      // Create the analytics reporting object
      const analyticsreporting = await google.analyticsreporting({
          version: 'v4',
          auth: auth,
      });
  
      // Fetch the analytics reporting
      const res = await analyticsreporting.reports.batchGet({...});
      return res.data;
  }
  </code></pre>
  
  <p>I already run out of options. Can someone help me with this?</p>