Login with Facebook Using Javascript

Login with Facebook using Javascript.
For more information visit :
https://developers.facebook.com/products/login/

<script>
window.fbAsyncInit = function() {
  FB.init({
    appId      : '*************427',
    cookie     : true,  // enable cookies to allow the server to access
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.0' // use version 2.0
  });
};
// Load the SDK asynchronously
(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function signupFB() {
      FB.login(
              function(response) {
                  if (response.status === 'connected') {
                      // Logged into your app and Facebook.     
                      getSignupInfo();
                    } else if (response.status === 'not_authorized') {
                      // The person is logged into Facebook, but not your app.
                     
                    } else {
                      // The person is not logged into Facebook, so we're not sure if
                      // they are logged into this app or not.
                     
                    }
              },
              {
                scope: 'public_profile,email'
              }
      );
}

function getSignupInfo() {   
    FB.api('/me', function(response) {
      console.log(response);
      signUpUser(response);
    });
}

function signUpUser(userInfo) {
    $.ajax({
          type: "POST",
          url: "http://127.0.0.1:81/test/api/social/signup-login",
          data: { firstname: userInfo.first_name, lastname: userInfo.last_name, email: userInfo.email,password:'',signupsource:1}
    }).done(function( resp ) {
          //console.log(resp);
          location = 'http://127.0.0.1:81/test/admin/index/events';
    });
}
</script>

<body>
<button id="Login" onclick="signupFB()">Login With Facebook</button>
</body>

View More:-
Login With LinkedIn Using javascript
Login With GooglePlus Using Javascript

Comments

Popular posts from this blog

Post data by ajax using coldfusion component

Create CSV file in Coldfusion Using CFFile