Wednesday, 26 April 2017

How to get email and profile information from OAuth2 Google API?

I'm trying to retrieve the name of a logged in user using Google API Node.js Client, using OAuth2 API.

Following the usage example, I managed to do the login, but I can't find a way to get the profile information.

I'm not using People API nor Plus API, cause as far as i know, OAuth2 includes https://www.googleapis.com/auth/userinfo.profile, which should be enough for the task.

I have seen some similar questions and tried the solutions of this one but it didn't work, maybe it's too old (?)

With the npm package googleapis how do I get the user's email address after authenticating them?

Looking at other API's like Google Sheets, it's possible to call their functions like this:

var google = require('googleapis');
var sheets = google.sheets('v4');

...

sheets.spreadsheets.values.get({
    auth: auth,
    spreadsheetId: file_id,
    range: my_ranges,
  }, function(err, response){
       ...
     }
);

But it seems that OAuth2 doesn't work like that...



via amlibtest

No comments:

Post a Comment