I have the following code snippet, to retrieve user information when he uses gmail to login:
oauth2Client.getToken(code, function(err, tokens) {
if (err) {
console.log(err);
res.send(err);
return;
}
console.log("allright!!!!");
var plus = google.plus('v1');
var API_KEY = 'AXXXXXXXXXXXXXXXXXXXXXXXXXU'; // specify your API key here
plus.people.get({
auth: API_KEY,
userId: 'me'
}, function (err, user) {
console.log(user);
});
res.send(tokens);
});
Gmail and google+ APIs are both enabled. The user object which is retrieved is returning 'null', while it should return the user information object. Why is this so? Am i giving correct value for userId? How can i retrieve information like gmail address, first name, last name, etc.
It seems you are using the client wrong, here you have an example taken from the Node.js client repo:
You have to pass the
oauth2Client
instance through theauth
property, notAPI_KEY
.Did you check the
err
argument? I guess you are getting null because it is returning an error, something like you did not authenticate.