Shane Shane - 1 year ago 1120
Javascript Question

Facebook Messenger API: Trouble setting up a webhook

I am trying to set up a web hook for the new Facebook Messenger bot platform and am receiving this error:

The URL couldn't be validated. Response does not match challenge, expected value = '364011207', received='<html> <header> <s...'

The callback URL is SSL certified. I have created a .html file on the server which contains a script in the header with:

app.get('/webhook/', function (req, res) {
if (req.query['hub.verify_token'] === 'my_token_here') {
res.send('Error, wrong validation token');

I have tried multiple variations and consulted the Facebook documentation on webhooks all day but am not having any success.

Any help is greatly appreciated.

Answer Source

I came across a fix. I scrapped my js attempt and created a new php file with the following code:


$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];

if ($verify_token === 'my_token_code') {
echo $challenge;

I got this code from the first 10 minutes of this video:

Still curious to know what i was doing wrong in my js attempt if anybody knows...