Facebook Messenger API: Trouble setting up a webhook

独自空忆成欢 提交于 2019-12-04 10:11:44

问题


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

The URL couldn't be validated. Response does not match challenge, expected value = '364011207', received='

Resources

https://developers.facebook.com/docs/messenger-platform/quickstart

https://developers.facebook.com/docs/messenger-platform/webhook-reference#common_format

Any help is greatly appreciated.


回答1:


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

<?php

$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: https://www.facebook.com/marketingdevelopers/videos/883648801749520/




回答2:


That code is node.js code and should be run on the server not in a <script> tag in your HTML.

Here's a simple walk through of setting up the messenger bot with node.js: https://github.com/voronianski/simon-le-bottle

Essentially you need to make sure you have a host that supports node.js applications and run it as such. It will not work inside of HTML.




回答3:


I just resolved this problem by adding '/webhook' in the callback URL...




回答4:


@shane

webhook: function(req, res) {

   if (req.query['hub.verify_token'] === 'tokentoken') {
      res.send(req.query['hub.challenge']);
   } else {
      res.send('Error, wrong validation token');    
   }
}

Note sure what exactly you're doing. but this is what I did and it's working.

I've tested using ngrok server as I don't have a domain name and the callback URL is https://werwrwetwtw.ngrok.io/webhook

Hope this helps!




回答5:


If you're running this as a Node.js application, and you're coming from the The Facebook Quickstart Guide mentioned in the question, you'll have to point the webhook URL to [your-server-root]/webhook. Notice this part of the tutorial:

// Adds support for GET requests to our webhook
app.get('/webhook', (req, res) => {
    ...
    // Responds with the challenge token from the request
    res.status(200).send(challenge);
});



回答6:


Not sure if this help, but the query parameters that FB send are with underscore not dot e.g. :

  • hub_verify_token
  • hub_mode
  • hub_challenge

P.S.

Sorry, this is valid for PHP



来源:https://stackoverflow.com/questions/36595183/facebook-messenger-api-trouble-setting-up-a-webhook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!