Using the Google People API with Cloud Functions for Firebase

I'm trying to get a contact list from the Google People Cloud API for Firebase, but I only get an empty object as a response. Any thoughts? Cloud function code below:

var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

var google = require('googleapis');
var people = google.people('v1');

exports.contacts = functions.https.onRequest((request, response) => {
  admin.database().ref('/settings/contacts/credentials/serviceAccount').once("value", function(data) {
    var authClient = new google.auth.JWT(
      data.child('clientEmail').val(),
      null,
      data.child('privateKey').val(),
      ['https://www.googleapis.com/auth/contacts'],
      null
    );

    authClient.authorize(function (err, tokens) {
      if (err) {
        console.error(err);
        response.end();
        return;
      }

      // Make an authorized request to list contacts.
      people.people.connections.list({auth: authClient, resourceName: 'people/me'}, function(err, resp) {
        if (err) {
          console.error(err);
          response.end();
          return;
        }

        console.log("Success");
        console.log(resp);
        response.send(resp);
      });

    });
  });

});

      

In the Firebase console logs, the success message is printed along with an empty JSON object. It seems to login successfully, so not really sure what's going on. Any help would be greatly appreciated.

+3
node.js firebase google-cloud-functions google-people


source to share


No one has answered this question yet

Check out similar questions:

81
Cloud functions to launch Firebase on time?
26
Firebase cloud functions are very slow
five
NodeJs, Mocha and Mongoose
2
Registration of glass delivery time notification using the node
2
firebase cloud function Google cloud storage API error
2
Firebase function get download url after successfully saving image to firebase cloud storage
1
Firebase - NodeJS: Domain Transfer with OAuth2 for Google API
0
Google Suite - Google API Access - Client is unauthorized to obtain access tokens using this method
0
YouTube API error, Node.js
0
Access from firebase functions to an application on GCE behind Identity Aware Proxy



All Articles
Loading...
X
Show
Funny
Dev
Pics