Another useful bit (PHP snippet this time) related to Facebook Page Apps:
1 2 3 4 5 6 7 8 |
$signed_request = $_POST['signed_request']; list($encoded_sig, $payload) = explode('.', $signed_request, 2); $sig = base64_decode(strtr($encoded_sig, '-_', '+/')); $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {echo '<!--Unknown algorithm. Expected HMAC-SHA256->';} $expected_sig = hash_hmac('sha256', $payload, APP_SECRET, $raw = true); if ($sig !== $expected_sig) {echo '<!--Bad Signed JSON signature!-->';} $liked = $data['page']['liked']; |
When used in your application this results in a $like
variable which will have a value of 0 or 1 depending on whether the Facebook user has liked the page on which the application resides.