Check If The User Likes (Fan Of) Your Facebook Page When Landing On Your Page Tab


Check when user landed on facebook fan page tab, Wheather he is fan of this page or not ?



A lot of developers and admins Facebook pages don’t know that they can detect whether the visiting user is already a fan of the page or not.

When the user visit your Page Tab, Facebook will send you the usual signed_request but with additional parameter called page.

When a user navigates to the Facebook Page, they will see your Page Tab
added in the next available tab position. Broadly, a Page Tab is 
loaded in exactly the same way as a Canvas Page. When a user selects 
your Page Tab, you will received the signed_request parameter with 
one additional parameter, page. This parameter contains a JSON object 
with an id (the page id of the current page), admin (if the user is a 
admin of the page), and liked (if the user has liked the page). 
As with a Canvas Page, you will not receive all the user information 
accessible to your app in the signed_request until the user authorizes 
your app.




<?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!";

}

?>

Comments

Popular posts from this blog

How to check browser cookie enabled with php and javascript

cookie and subdomains

Output buffering in php