GoogleUser is not defined - How to solve it?

0

Hello, I am using google Oauth2 for login and I do not throw anything, I put everything as indicated in your documentation but nothing, run by googleUser console and say that (is not defined)

 <script>

  function onSignIn() {
  /*var profile = googleUser.getBasicProfile();
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
  var id_token = googleUser.getAuthResponse().id_token;
  console.log('id_token');*/
  const googleUser = gapi.auth2.getAuthInstance().currentUser.get();
  const profile = googleUser.getBasicProfile();
  console.log('Name: ' + profile.getName());

}

the lines commented only because it was tested in that other way please someone who can help me?

    
asked by ali gustavo morgado jimenez 01.12.2018 в 05:58
source

1 answer

2

after so much searching and searching on the internet and not finding anything, take the decision to solve it on my own and achieve it halfway.

At least it throws me the data and with that I can work maybe it is not the most correct but it is a solution and I will share it.

I hope someone serves you.

Just change this code:

function onSignIn(googleUser) {
   var profile = googleUser.getBasicProfile();
   console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
   console.log('Name: ' + profile.getName());
   console.log('Image URL: ' + profile.getImageUrl());
   console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}

For this one that you program.

function onSignIn() {

    const gapix1 = gapi.auth2.getAuthInstance();
    const gapix2 = gapix1.currentUser.get();
    const gapix3 = gapix2.getBasicProfile();

    const getId = gapix3.Eea; 
    const getName = gapix3.ofa +" "+ gapix3.wea; 
    const getName1 = gapix3.ofa;
    const getName2 = gapix3.wea;
    const getEmail = gapix3.U3;
    const getImageUrl = gapix3.Paa;
    const getidToken = gapix2.getAuthResponse().id_token;


  console.log('ID: ' + getId); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + getName);
  console.log('Name1: ' + getName1);
  console.log('Name2: ' + getName2);
  console.log('Image URL: ' + getImageUrl);
  console.log('Email: ' + getEmail); // This is null if the 'email' scope is not present.
  console.log(getidToken); 

}

And the button code for this:

<div class="g-signin2" onclick="setInterval(function(){ onSignIn(); }, 10000);" data-width="300" data-height="40" data-longtitle="true">
    
answered by 01.12.2018 в 08:22