970_90

Tuesday, 11 August 2015

How to logout from facebook with javascritp SDK - FB.logout


How to logout from facebook with javascritp SDK - FB.logout

Following are  code snippets to logout from Facebook:
<script>window.fbAsyncInit = function() {
                FB.init({
                    appId      : "FACEBOOK_APPLICATION_ID", 
                    status     : true, 
                    cookie     : true,
                    xfbml      : true,
                    oauth      : true                    
                });
                FB.getLoginStatus(function(response) {
                if (response && response.status === 'connected') {
                    FB.logout(function(response) {
                       /** Afer logout, Refresh the Page **/ 
                       console.log('Logout Successfully.');
                       document.getElementById('currentStatus').innerHTML='Logout from facebook Successfully.';
                       //document.location.href='/';
                       /** Afer logout, Refresh the Page **/                        

                    });
                }else{
                    //document.location.href='/';                    
                    document.getElementById('currentStatus').innerHTML='You are NOT LOGIN in Facebook.';
                    console.log('You are not login in Facebook.')
                }
            });


            }; 

            (function(d){
                var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
                js = d.createElement('script'); js.id = id; js.async = true;
                js.src = "//connect.facebook.net/en_US/all.js";
                d.getElementsByTagName('head')[0].appendChild(js);
            }(document));
        </script>
        <h2 id="currentStatus">
Please wait...</h2>

No comments:

Post a Comment