How to check IF user has ALREADY liked the facebook page?

前端 未结 2 991
我寻月下人不归
我寻月下人不归 2020-12-06 06:57

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)

相关标签:
2条回答
  • 2020-12-06 07:26

    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.

    public function userIsFan() {
        $sr = $this->getSignedRequest();
        if($sr && is_array($sr)){
            if(array_key_exists('page', $sr)){
                return $sr['page']['liked'] == 1;
            }
        }
        return 0;
    }
    
    0 讨论(0)
  • 2020-12-06 07:48

    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.

    0 讨论(0)
提交回复
热议问题