Skip to content

Instantly share code, notes, and snippets.

@tracend
Created April 20, 2011 02:29
Show Gist options
  • Save tracend/930226 to your computer and use it in GitHub Desktop.
Save tracend/930226 to your computer and use it in GitHub Desktop.
Facebook JS-SDK: Check if the user has liked a page
FB.api({ method: 'pages.isFan', page_id: '{PAGE_ID}' }, function(response) {
if (response) {
alert("user has liked the page");
} else {
alert("user has not liked the page");
}
});
Copy link

ghost commented Dec 17, 2014

Same code but it's not working anymore for me.

I saw this working this few hours ago and now I always got 'false' as callback.

Any suggestion?

@rahulatoz
Copy link

Same code i am using but its not wokring
You can see my whole code

window.fbAsyncInit = function() {
FB.init({
appId : '1100886646641860',
xfbml : true,
version : 'v2.6'
});

  FB.Event.subscribe('edge.create',
    function(href, widget) {
    //alert('Ti piace ' + href);         
    //document.getElementById('fb-like').style.display = "none";          

    //var x = document.getElementsByTagName("button")[0].getAttribute("title");    
    // alert(x);         
  });

FB.api({ method: 'pages.isFan', page_id: '100012125951339' }, function(resp) {
if (resp) {
  alert('You like it.');
} else {
  alert("You don't like it.");
}

});

};

(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'));

@webhacking
Copy link

@rahulatoz This code not supported v2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment