Created
December 6, 2012 16:57
-
-
Save cdnsteve/4226022 to your computer and use it in GitHub Desktop.
JavaScript: Facebook check if user likes page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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