Thursday 1 December 2016

login with google with php example

login with google with php example

//login with google with php example

<script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
<script src="https://apis.google.com/js/api:client.js"></script>
<script>
var startApp1 = function() {
    gapi.load('auth2', function(){
      // Retrieve the singleton for the GoogleAuth library and set up the client.
      auth2 = gapi.auth2.init({
        client_id: 'your google client id',
        cookiepolicy: 'single_host_origin',
        // Request scopes in addition to 'profile' and 'email'
        //scope: 'additional_scope'
      });
      attachSignin1(document.getElementById('gplus1'));
    });
  };

  function attachSignin1(element) {
    console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {

var facebook_email  = googleUser.getBasicProfile().getEmail();
var facebook_name = googleUser.getBasicProfile().getName();
var get_role_id = 2;
var facebook_login = 0;
  var google_login = 1;

        
               $.ajax({
url:"common/facebook_login",
method:"POST",
data:{facebook_email:facebook_email,facebook_login:facebook_login,google_login:google_login},
success: function(res){
if(jQuery.trim(res)=="Your are successfully login"){
//jQuery('.all_error_here').text(res);
//$("#errorDialog").modal('show');
location.reload();
}else{
jQuery('.all_error_here').text(res);
$("#errorDialog").modal('show');
}

}
});

        }, function(error) {
          alert(JSON.stringify(error, undefined, 2));
        });
  }
  </script>
 

  <script>startApp1();</script>
 
  <button id="gplus1" data-dismiss="modal" data-toggle="modal" class="btn btn-block radius-6 twitter-btn"><i class="fa fa-google-plus"></i> Sign in with Google+</button>

//login with google with php example

No comments:

Post a Comment

Thank You For Comment