Basically I would like to know if my visitor is already a fan of my Facebook Page 开发者_运维百科or not.
I tried looking a while andpages.isFan
is the best solution so far.
http://developers.facebook.com/docs/reference/rest/pages.isFan/
But pages.isFan
need user id (uid
), which I can only get if they installed or grant access to my Facebook apps.
My question is, is there a way just to get the uid
of my visiting user without ask them to grant access to my Facebook apps?
This code should do the trick:
$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"])) {
/* Not Fan */
}
else {
/* Fan */
}
More methods can be found here: http://www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/
精彩评论