Skip to content

Instantly share code, notes, and snippets.

@tominon
Created October 16, 2017 21:07
Show Gist options
  • Save tominon/a1f85b4a5d236b6f45e5e78a34e5b568 to your computer and use it in GitHub Desktop.
Save tominon/a1f85b4a5d236b6f45e5e78a34e5b568 to your computer and use it in GitHub Desktop.
Facebook Webhook handler example
<?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);
@dlopez-evolmind
Copy link

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.

@tominon
Copy link
Author

tominon commented Sep 22, 2023

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

@dlopez-evolmind
Copy link

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