views:

440

answers:

1

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"&gt;&lt;/script&gt;
<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?

A: 

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

    });
  }
Tytus

related questions