Mark
Mark

Reputation: 1126

Showing/hiding content from FB fans on my own site

So I'm adding the 'like' button to my site and I've got it to display "Thank you for liking example.com" and "You seemed to have unliked example.com" using edge.create;

FB.Event.subscribe('edge.create',
    function(response) {
        document.getElementById("demo").innerHTML=('Thank you for liking example.com');
}
);
FB.Event.subscribe('edge.remove',
    function(response) {
        document.getElementById("demo").innerHTML=('You seemed to have unliked example.com');
}

);

However this method only works when the button is clicked. If a visitor comes to my site and has already liked example.com I would like to show them a message without them having to click anything.

I know this is possible to do on a facebook page but what about on my own site. Any ideas? Cheers

Upvotes: 1

Views: 207

Answers (1)

Ted S
Ted S

Reputation: 337

Certainly possible using FB.getLoginStatus

FB.getLoginStatus(function(response) {
  if (response.authResponse) {
    // logged in and connected user, someone you know
  } else {
    // no user session available, someone you dont know
  }
});

http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

Keep in mind that this refers to a user being logged in to your app and / or Facebook. If someone is not logged in to Facebook, they will of course return FALSE and thus your message should reflect to have them connect OR login.

Upvotes: 2

Related Questions