Using Google Identity, What do I use instead of googleUser.getBasicProfile() to retrieve a user's email address and full name?

47 Views Asked by At

my question is regarding the deprecation of google api for googleUser.getBasicProfile() and what to use instead to get the user's information.

  • I am setting an html webpage up such that a user can login using a google email. This uses a google button and google identity.
  • Once they have logged in they are redirected to a new html page.
  • I want to then display on the html page the logged in user's information, such as the email address they used to login and their name retrieved from their google email account. I noticed that the variable is not being stored locally when I attempt to.
function handleSignInSuccess(googleUser) {
    var profile = googleUser.getBasicProfile();
    var email = profile.getEmail();

    localStorage.setItem("email", email);

I tried to use ID token instead but it didn't work for me.

Tried using ID token: var id_token = googleUser.getAuthResponse().id_token; Tried suggestions from Google's own pages but they must be the deprecated api pages and can't find specific pages for alternative commands. I would appreciate being pointed in the direction of newer documentation.

Also tried getting the account information from signInSuccess callback like this:

function signInSuccess(googleUser) {
    const id_token = googleUser.getAuthResponse().id_token;
    const email = getEmailFromToken(id_token);
}
0

There are 0 best solutions below