开发者

How do I check if a user is a fan of my facebook page on my website?

开发者 https://www.devze.com 2022-12-20 10:57 出处:网络
I want to check if my users are fans of my facebook开发者_如何学Go page.I think something like this should do it:

I want to check if my users are fans of my facebook开发者_如何学Go page. I think something like this should do it:

    <script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script>
<script type="text/javascript">FB.init("my api key","xd_receiver.htm");</script>
    <script type="text/javascript">
    //<![CDATA[ 
    FB_RequireFeatures(["Api"], function(){

    var api = FB.Facebook.apiClient;
            api.pages_isFan(PAGE_ID,gigyaUser.FACEBOOK_USER_ID,function(response){
         alert(response);
    });

    });

    //]]>
    </script>

However, for some reason I keep getting null even though the user is in fact a fan of the page. Am I missing something?


I think you almost had that correct. This snippet works great for me.

assumes: 1. fanPageUID = the fan page's uid 2. and user UID is the UID of the user 3. (and you have an active session)... this may be the hard part, but not part of this question.

  function checkifFan() {
    FB_RequireFeatures(["Api"], function(){
    var api = FB.Facebook.apiClient.pages_isFan(fanPageUID,userUID,function(response){
        if (response==false) {
          setTimeout('checkifFan()', 300); //every 300ms check if they have pressed fan
        }
        else {
          location.reload();
        }
    });

    });
  }


You can also check that a user is a fan of your website by the following script:

<fb:login-button scope="user_likes">
  Grant Permissions to Allow access to Likes  
</fb:login-button>

<button onclick="checkDoesLike()">Check if user Likes the Page</button>

<h1>Like this Application's Page</h1>
<fb:like-box profile-id="your_page_id"></fb:like-box>

<script>
  window.checkDoesLike = function() {
    FB.api({ method: 'pages.isFan', page_id: 'your_page_id' }, function(resp) {
      if (resp) {
        Log.info('You like the Application.');
      } else {
        Log.error("You don't like the Application.");
      }
    });
  };
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号