Or you can use fbml if you whant for example show some content if they are fan or made some dinamic stuff.
example:
<fb:fbml version="1.1">
<fb:visible-to-connection>This part is visible for fans only!
<fb:else>This part is visible for non-fans</fb:else>
</fb:visible-to-connection>
</fb:fbml>
Here's another approach that relies on the signed_request POST variable that Facebook sends to every tab app page (if you have the "OAuth 2.0 for Canvas" advanced option turned on.
The nice thing about this is you don't need to send another fql.query.
While pages.isFan is still working for me, you can use the FQL page_fan table with the new PHP-SDK:
$result = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid FROM page_fan WHERE uid=$user_id AND page_id=$page_id"
));
if(!empty($result)) // array is not empty, so the user is a fan!
echo "$user_id is a fan!";
From the documentation:
To read the page_fan table you need:
any valid access_token if it is public (visible to anyone on Facebook).
user_likes permissions if querying the current user.
friends_likes permissions if querying a user's friend.
Or you can use fbml if you whant for example show some content if they are fan or made some dinamic stuff.
example:
Here's another approach that relies on the signed_request POST variable that Facebook sends to every tab app page (if you have the "OAuth 2.0 for Canvas" advanced option turned on.
The nice thing about this is you don't need to send another fql.query.
UPDATE 2:
To check if the current user is a fan of the Facebook page on landing at your tab check this answer.
UPDATE:
You can use the
likes
connection to check if a user is a fan of a page:This would return either an empty data array:
Or if fan:
So this is how we check using the PHP-SDK:
Similar script usingJS-SDK:
Code taken from my tutorial.
While
pages.isFan
is still working for me, you can use the FQLpage_fan
table with the new PHP-SDK:From the documentation: