CheckingLikeOfCocaCola

by dmcs

HTML

<html>
     <head></head>  
     <body>          
         <div id="fb-root"></div> 
         <div id="container_notlike"> YOU DONT LIKE </div>  
         <div id="container_like"> YOU LIKE </div>
     </body>
</html>

JavaScript

$(document).ready(function() {
    FB.getLoginStatus(function(response) {
        if (response.session) {
            var user_id = response.session.uid;
            var page_id = sysinventive; //coca cola       
            var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id;
            var the_query = FB.Data.query(fql_query);
            the_query.wait(function(rows) {
                if (rows.length == 1 && rows[0].uid == user_id) {
                    $("#container_like").show(); //            
                } else {
                    $("#container_notlike").show();
                    //and here you could  get the content for a non liker in ajax...          
                }
            });
        } else {
            // user is not logged in   
        }
    });
});

  // Load the SDK Asynchronously
  (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));

window.fbAsyncInit = function() {

FB.init({
    appId: 300174290018567,
    status: true,
    cookie: true,
    xfbml: true
});
};