-2

How to check whether we are fans fanpage or fanpages

id pass on to the page method as follows:

page_id or page_id, page_id2, page_id3

function isFan(a) 
{
    FB.api('me/likes/'+a ,function(response) 
    {
    if (response.data.length == 0) 
    {
        $("#myModal2").modal()   
    }else{
        //OK i like
    }
    });

}    
Sam
  • 7,252
  • 16
  • 46
  • 65
Kamil
  • 21
  • 6

2 Answers2

0

Well, I don't realistically think you can do the OR without some processing of your own. But you could use an fql query to retrieve a list of all the pages someone likes, then check if they match each one.

e.g // this would give you all a users fan page likes

  FB.api('/fql?q=' + urlencode("select page_id from page_fan where uid = me()")function(res){

 });

Then you would use your own code to validate that your lists are in the returned data. Alternatively you could do something like(make sure to urlencode the query)

  fql?q={"isFan":"select page_id from page_fan where uid = me()","myMatches":"select page_id from #isFan where page_id in (page_id1,page_id2)"}

the returned "myMatches" array in the JSON result would then contain only the likes against the ids you specify. So check the length of this result set, against the length of the number of page_ids you had initially.

   //pseudo code so prob some syntax errors here
   var page_ids = Array(1,2,3);
   var valid = true;
   var myQuery = ''; // <- your fql query here
   FB.api('/fql?q=' + myQuery, function(res)}
         var matches = res['myMatches'];
         if(matches.length == page_ids.length){
            valid = true;
         }elseif(matches.contains(single_id)){
            //some single id if you only want to check one
            valid = true;
         }else{
            valid = false;
         }
    });

The above could clearly be optimised, but it's just a starting point for you

TommyBs
  • 9,354
  • 4
  • 34
  • 65
0

Ok I did it, how would anyone ever need.

function isFan(a) 
{
    var myString = a; 
    var fan_page_id = myString.split(',');

    for (var i=0;i<fan_page_id.length;i++)
    { 
        FB.api('me/likes/'+fan_page_id[i] ,function(response) 
        {
            if (response.data.length == 0) 
            {
                $("#myModal2").modal()   
                brake;
            }else{
                //OK i like
            }
        });
    }
}    
Kamil
  • 21
  • 6