Skip to content

Instantly share code, notes, and snippets.

@cdnsteve
Created December 6, 2012 16:57
Show Gist options
  • Save cdnsteve/4226022 to your computer and use it in GitHub Desktop.
Save cdnsteve/4226022 to your computer and use it in GitHub Desktop.
JavaScript: Facebook check if user likes page
/* Source: http://stackoverflow.com/questions/5093398/how-to-check-if-a-user-likes-my-facebook-page-or-url-using-facebooks-api
*/
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment