I used to use the flowing code to check if the user is a fan of my page or not while he is on my facebook page. Now I want to check if the user is a fan of my facebook page while he is on my WEBSITE.
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
echo "You are not a fan!";
} else {
echo "Welcome back fan!";
}
?>
I read through the facebook documentation, but I was not able to find suitable answer.
Help ?
I do not want to deal with any application permissions with facebook. How can I approach this through only php ?
You will not get
pagedetails if visiting application not in Page Tab.You may achieve that with simple FQL query to
page_fantable (knowing the id of the Facebook Page of course):Or by querying Graph API for
likesconnection ofuserobject:Both of those ways require
user_likespermission granted by user.To get the same details for user’s friends ask for
friends_likespermission and substituteme/me()with friend id.Update: (just to describe what you asked in comments)
There are cases that requiring
user_likesmay be unnecessary due to nature of flow, if you only need to know that user will/need to like some URL and/or Facebook Page.You may do so by subscribing (
FB.subscribe) toedge.createevent which will be triggered once user will like the page (for un-like there isedge.removeevent).Beware that this is only reliable in cases user didn’t liked that content before since
edge.createonly fired on time of user’s action.