Skip to content Skip to sidebar Skip to footer

How To Check If User Has Already Liked The Facebook Page?

I have a like button on my website (which is for users to like the fb fan page). If the user clicks like, I check to see if the even has been fired (event subscribe), and then disp

Solution 1:

If you use the facebook php API. i've came up with this short function that u can include inside the base_facebook.php file into the class BaseFacebook.

publicfunctionuserIsFan() {
    $sr = $this->getSignedRequest();
    if($sr && is_array($sr)){
        if(array_key_exists('page', $sr)){
            return$sr['page']['liked'] == 1;
        }
    }
    return0;
}

Solution 2:

Make sure you are using xfbml, this one works for me

FB.Event.subscribe('auth.authResponseChange', function(response) {
        FB.api('/me/likes/[page_id]',
          function(response) {
              //console.log(response); - see what the response is on your console.if(response.data[0])
                //use script to display your content alert("Liked");else// just do nothing, display like button alert("Not yet liked");
          }
        );

    });

page_id will be the id not the name of your page, to find out the id, just visit http://graph.facebook.com/[your fb page name]

hope this helps someone in the future.

Post a Comment for "How To Check If User Has Already Liked The Facebook Page?"