如何检查用户是否是我网站上Facebook页面的粉丝?

问题描述:

我想检查我的用户是否是我的Facebook页面的粉丝.我认为应该这样做:

I want to check if my users are fans of my facebook 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>

但是,由于某种原因,即使用户实际上是该页面的支持者,我仍会得到null.我想念什么吗?

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.

假设: 1. fanPageUID =风扇页面的uid 2.用户UID是用户的UID 3.(并且您有一个活跃的会话)...这可能是困难的部分,但不是此问题的一部分.

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

    });
  }