title: Error: Could not load the default credentials (Firebase function to firestore)
body: <p>I am attempting to write an onCall function for Firebase Cloud Functions that performs advanced querying tasks on a firestore database (i.e. checking a text query up against AutoML natural lang to get a category, etc) but I keep running into a problem trying to query the database from the function:</p>
  
  <pre><code>Error getting documents ::  Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
      at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
      at &lt;anonymous&gt;
      at process._tickDomainCallback (internal/process/next_tick.js:229:7)
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp();
  const db = admin.firestore();
  
  exports.query = functions.https.onCall((data, context) =&gt; {
      const text = data.text;
      var results = [];
      const promise = db.collection('providers').get()
      promise.then((snapshot) =&gt; {
          console.log('marker');
          snapshot.forEach((doc) =&gt; {
              results.push({id: doc.id, data: doc.data()});
          });
          console.log('yessir');
          return {results: results};
      }).catch((err) =&gt; {
          console.log('Error getting documents :: ', err)
          console.log('nosir');
          return {results: "no results"};
      });
  });
  </code></pre>
  
  <p>Longer output:</p>
  
  <pre><code>Function execution started
  Function execution took 8ms, finished with status code: 200
  Error getting documents :: (etc, same error)
  nosir
  </code></pre>
  
  <p>Example 2 (no change in running):</p>
  
  <pre><code>Function execution started
  Function execution took 1200 ms, finished with status code: 200
  marker
  yessir
  </code></pre>
  
  <p>I can't figure out where this problem is coming from or how to resolve it.
  Any help?</p>
  
  <p>Regards.</p>