Login With Google Plus Using Javascript

Login With Google Plus Using Javascript
More information visit:
https://developers.google.com/+/web/api/javascript

<!-- Place this asynchronous JavaScript just before your </body> tag --- Google SignIn-->
<script type="text/javascript">
    (function() {
           var po = document.createElement('script'); po.type = 'text/javascript';
           po.async = true;
           po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback';
           var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
         })();
</script>


<script type="text/javascript">

$(document).ready(function(e) {
           var po = document.createElement('script'); po.type = 'text/javascript';
          po.async = true;
           po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback';
           var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
 });

function signupGoogle()
{
  var myParams = {
    'clientid' : '********6936-vg5vrmb58urppmg5lv40hp8p2kn7bhl6.apps.googleusercontent.com',
    'cookiepolicy' : 'single_host_origin',
    'callback' : 'loginCallback',
    'scope' : 'https://www.googleapis.com/auth/plus.login',
    'requestvisibleactions' : 'http://schema.org/AddAction'
  };
  gapi.auth.signIn(myParams);
}

function loginCallback(result)
{
    if(result['status']['signed_in'])
    {
        var request = gapi.client.plus.people.get(
        {
            'userId': 'me'
        });
        request.execute(function (resp)
        {
            var email = '';
            if(resp['emails'])
            {
                for(i = 0; i < resp['emails'].length; i++)
                {
                    if(resp['emails'][i]['type'] == 'account')
                    {
                        email = resp['emails'][i]['value'];
                    }
                }
            }
            var firstName = resp['name'].givenName;
            var LastName = '';
            if(resp['name'].familyName != '' || resp['name'].familyName != 'undefined'){
                LastName = resp['name'].familyName;
            }

            var address = '';
            if(resp['placesLived'])
            {
                address = resp['placesLived'][0].value;
            }
       
            $.ajax({
                  type: "POST",
                  url:  "/api/social/signup-login",
                  data: { firstname: firstName, lastname: LastName, email: email,password:'',signupsource:2,address:address}
            }).done(function( data ) {
                  //console.log(data);
                  location =  '/admin/index/events';
            });
           
        });

    }else {
        // Update the app to reflect a signed out user
        // Possible error values:
        //   "user_signed_out" - User is signed-out
        //   "access_denied" - User denied access to your app
        //   "immediate_failed" - Could not automatically log in the user
        console.log('Sign-in state: ' + result['error']);
      }

}


function onLoadCallback()
{
    gapi.client.setApiKey('AIzaSyDqijwlBuWfkjgF15MQ67fqRzC7CqmTpZ4');
    gapi.client.load('plus', 'v1',function(){});
}
</script>

 <body>
 <button id="login" onclick="signupGoogle()">Login With Google</button>
</body>

View More:-
Login With LinkedIn Using Javascript
Login with facebook using Javascript

Comments

Popular posts from this blog

Create CSV file in Coldfusion Using CFFile

Post data by ajax using coldfusion component