Created
October 16, 2017 21:07
-
-
Save tominon/a1f85b4a5d236b6f45e5e78a34e5b568 to your computer and use it in GitHub Desktop.
Facebook Webhook handler example
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 | |
/** | |
* Facebook Webhook handler example | |
* | |
* @see https://fb.me/webhooks | |
* @author Tom (https://github.com/tominon) | |
*/ | |
$verifyToken = 'VERIFY_TOKEN'; // You will specify it when you enable the Webhook for your app | |
$appSecret = 'APP_SECRET'; | |
// Handle verification request | |
if (isset($_GET['hub_mode']) && $_GET['hub_mode'] === 'subscribe') { | |
if ($_GET['hub_verify_token'] === $verifyToken) { | |
echo $_GET['hub_challenge']; | |
exit; | |
} | |
} | |
// Validate the integrity and payload and it's origin | |
$payload = file_get_contents('php://input'); | |
if (isset($_SERVER['HTTP_X_HUB_SIGNATURE']) && hash_equals(explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE'])[1], hash_hmac('sha1', $payload, $appSecret))) { | |
// Handle payload | |
$data = json_decode($payload, true); | |
file_put_contents(time().'-webhook.php', $payload); | |
exit; | |
} | |
header('HTTP/1.1 500 Internal Server Error'); | |
exit(1); |
Hi, this is a 6 year old example and may not work anymore. Get the latest information here: https://developers.facebook.com/docs/graph-api/webhooks
Hi, this is a 6 year old example and may not work anymore. Get the latest information here: https://developers.facebook.com/docs/graph-api/webhooks
Hello,
yes yes I know, I have followed the steps of the documentation that you pass me but I get empty data, I have been able to link the webhook and I receive the hub, but then with each test I get nothing, would you know why?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I have followed all the steps and it seems that everything is well done, when I performed any test, I get empty data and I don't understand why.
If I use Postman I can collect all the data.
Please, I need to be able to solve this.
Best regards and thanks.