How to detect fan in facebook canvas page


facebookSometimes you may need to check whether logged in user or a particular user is a fan of a facebook page or not. If you want to detect facebook fan in facebook page then checkout my previous article How To Detect Fan Of A Facebook Page

But if you want to detect facebook fan in a canvas application then there is a simple api to check that:

include_once "facebook.php";
$facebook = new Facebook($api, $secret);
//check whether logged in user is fan of http://www.facebook.com/pages/Thinkdiffnet/314110374728
$isFan      =   $facebook->api_client->pages_isFan(314110374728);

//check whether 123456789 user is fan of http://www.facebook.com/pages/Thinkdiffnet/314110374728
$isFan      =   $facebook->api_client->pages_isFan(314110374728, 123456789);

if ($isFan){
   echo "User is a fan of 'http://www.facebook.com/pages/Thinkdiffnet/314110374728' ";
}

Here the first parameter is page id and second parameter is uid. If no uid is provided then this api used the logged in user id. This api doesn’t work for application about pages.

Reference: http://wiki.developers.facebook.com/index.php/Pages.isFan

Tags:
mahmud ahsan

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

7 Comments

  • quok
    July 13, 2010 at 9:25 pm

    hey there … thanks for the tip.

    But i can´t get that to work with the recent facebook php sdk. Seems like they changed a lot with the last release.

    Have you tried with the new sdk ?

    cheers
    quok

  • quok
    July 14, 2010 at 7:36 pm

    hey mahmud .. thx for the quick reply but i still can#t get it working like i want it.

    you example works fine (btw. thanks for this great tutorial) and with the workaround of emran (http://bit.ly/cT40vV) i was able to create an automatic redirect on the login url.

    What i would like to do is to check the Fan status of a user in a profile tab.
    is it possible to check the users fan status in a profile tab without redirecting him ?

    thanks a lot
    quarkus

  • Puzbie
    November 13, 2010 at 7:14 am

    Quok, did you ever work out how to do this?

    I have a PHP application which I want to run in a tab on a fan page.

    If I call

    $me = $facebook->api(‘/me’);

    I don’t get any info about the logged on user. Instead I get information about the app itself. How do I determine:

    A) Who the logged on user is.
    B) Whether they like the fan page.

    Great tutorials btw.

  • jaarek
    December 16, 2010 at 2:39 pm

    Hi, I used your code, and it doesn’t work, I’m using new php-sdk, can you show us a new example of it?

    thanks for all tutorials;)

  • Sergey
    December 21, 2010 at 11:39 pm

    Hi Mahmud,
    Is it possible to know using Graph API Who like some page?

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage