-
-
Save lonelycowboy/1263451 to your computer and use it in GitHub Desktop.
Facebook API - Detect if a user like's the app's 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
<?php | |
// Get Signed Request | |
$signed_request = $_REQUEST['signed_request']; | |
// Parse Signed Request | |
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; | |
} | |
// Display content depending on if the user likes the page or not. | |
if($signed_request = parsePageSignedRequest()) { | |
if($signed_request->page->liked) { | |
echo "YOU LIKE IT!"; | |
} else { | |
echo "LIKE TO VIEW CONTENT"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment