Friday 18 March 2016

Facebook SDK does not loading all.js

Facebook SDK doesn't loading and its getting failed

//connect.facebook.net/en_US/all.js

Facebook SDK is NOT Loading properly OR Facebook Login is not working in Few system, Might cause following reasons.
  1. Are you including JS with http OR https like below:
    http://connect.facebook.net/en_US/all.js
     OR
    https://connect.facebook.net/en_US/all.js
    If Yes, remove the "http:" OR "https://"
  2. Browser plugin is prevent to load the facebook js
  3. Blocking by Firewalls OR Antivirus
  4. Make sure you put that snippet in the <body></body> and not <head></head>
  5. facebook APPLICATION id  is in-correct.

Not Yet Fixed, Then below Code.

<script>
    function statusChangeCallback(response) {
        console.log('ok');
        if (response.status === 'connected') {
            console.log('You are login successfuly');
        } else if (response.status === 'not_authorized') {
            FB.login();
        } else {
            FB.login();
        }
    }

    // This function is called when someone finishes with the Login
    // Button.  See the onlogin handler attached to it in the sample
    // code below.
    function checkLoginState() {
        FB.getLoginStatus(function(response) {
            statusChangeCallback(response);
        });
    }

    window.fbAsyncInit = function() {
        FB.init({
            appId: 'FACEBOOK_APP_ID',
            cookie: true, // enable cookies to allow the server to access 
            // the session
            xfbml: true, // parse social plugins on this page
            version: 'v2.2' // use version 2.2
        });

        FB.getLoginStatus(function(response) {
            statusChangeCallback(response);
        });

        FB.login(function(response) {
            if (response.authResponse) {
                console.log('Welcome!  Fetching your information.... ');
                FB.api('/me', function(response) {
                    console.log(response);//Here you have login details
                    document.getElementById('loginId').style.display = 'none';
                    document.getElementById('alreadyLogin').style.display = 'block';

                });
            } else {
                document.getElementById('loginId').style.display = 'block';
                document.getElementById('alreadyLogin').style.display = 'none';
            }
        });

    };

    // 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'));
</script> 
<input id="loginId" onclick="checkLoginState()" style="display: none;" type="button" value="Click To Login in Facebook" />
<input id="alreadyLogin" style="display: none;" type="button" value="Already Login in Facebook" />