There are many resources and questions that are similar, but not exactly the same as me. Here I will review some of these solutions and explain them.
I have a user who is already registered with Google. By logging in, I mean that you are logged in and a cookie is present. Not registered in my application.
I just need to get an email address.
There are 3 ways to do this, which I saw, but does not work for me.
Way number 1:
auth2 = gapi.auth2.getAuthInstance();
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
Way number 2:
gapi.client.setApiKey(API_KEY);
gapi.client.load('plus', 'v1', function() {
gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
console.log(resp);
})
});
Way number 3:
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
console.log(resp.email);
})
});
On path # 2 and path # 3, the stack overflow says you need to use the token, not the api key. But the user has already registered, and I do not and can not get the token.
How to get EMAIL ALREADY registered user?
thank