login - getting user info google plus api -


how can public info of user google plus login button integrated on site, here code giving me email, need more info provide google plus :

  <div id="signin-button" class="show">      <div class="g-signin" data-callback="loginfinishedcallback"                         data-approvalprompt="force"                         data-clientid="9076269517.apps.googleusercontent.com"                         data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email"                         data-height="short"                         data-cookiepolicy="single_host_origin"> </div> 

java script :

  function loginfinishedcallback(authresult) {     if (authresult) {       if (authresult['error'] == undefined){         gapi.auth.settoken(authresult); // store returned token.         toggleelement('signin-button'); // hide sign-in button after signing in user.         getemail();                     // trigger request email address.       } else {         console.log('an error occurred');       }     } else {       console.log('empty authresult');  // went wrong     }   }  function getemail(){     // load oauth2 libraries enable userinfo methods.     gapi.client.load('oauth2', 'v2', function() {           var request = gapi.client.oauth2.userinfo.get();           request.execute(getemailcallback);         });   }    function getemailcallback(obj){     var el = document.getelementbyid('email');     var email = '';  if (obj['email']) {   email = 'email: ' + obj['email']; }  //console.log(obj);   // uncomment inspect full object.  el.innerhtml = email; toggleelement('email');   }     function toggleelement(id) {     var el = document.getelementbyid(id);     if (el.getattribute('class') == 'hide') {       el.setattribute('class', 'show');     } else {       el.setattribute('class', 'hide');     }   } 

i tried replacing email name, userid getting nothing these variables.

how can basic information of user when logged in through google plus.

similar how have loaded oauth2 v2 client package using gapi.client.load, use again load plus v1 client package. give number of packages , methods under gapi.client.plus namespace.

the plus api includes package load information people, including getting them user id or, since have authenticated you, can use special identifier "me".

full details , example given @ https://developers.google.com/+/api/latest/people/get, here (untested) similar function getemail() method full name:

 function getfullname(){   // load plus library people package , methods   gapi.client.load('plus', 'v1', function() {     var request = gapi.client.plus.people.get('me');     request.execute(getfullnamecallback);   }); };  function getfullnamecallback(obj){   var el = document.getelementbyid('email');   var name = '';    if (obj['displayname']) {     name = 'name: '+obj.displayname;   }    el.innerhtml = name;   toggleelement('name'); }; 

Comments