Sunday, 30 November 2014

Solution To Logout Facebook

               Facebook logout api  is not working. So I am providing alternate solution to logout
       facebook.

       Test below code:
               Create a jsp file in webcontent. copy and paste the below code.

       <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
       pageEncoding="ISO-8859-1"%>
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
       /TR/html4/loose.dtd">
       <html>
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
       <script type="text/javascript">
       function facebookLogout() {
        FB.getLoginStatus(function(response) {
       if (response.authResponse) {
            FB.logout(function() {
              window.location = document.URL + "?logout=1";
       });
            return false;
       } else {
            window.location = document.URL + "?logout=1";
            return false;
          }
       });
       }
      </script>
      </head>
      <body>
      <div id="fb-root"></div>
   
      <p><a href="javascript:facebookLogout();">Logout</a></p>
     
      <div class="fb-login-button" data-max-rows="1" data-size="xlarge" data-show-faces="false"    
      data-auto-logout-link="true"></div>
  
      <!-- <fb:login-button></fb:login-button> -->
  
     <script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId : 'XXXXXXXXXXX',
          status: true,
          cookie: true,
          xfbml : true,
          oauth : true,
        display :true,
        });

        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
       };

      (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>
      </body>
      </html>