dqzuo0327 2017-08-13 16:58
浏览 111
已采纳

来自facebook messenger机器人的空消息

I followed the guide to build a facebook messenger bot from here

but in my software I receive alway an empty response.

here my bot code:



    define('PAGE_TOKEN',"xxx");
    define('VERIFY_TOKEN',"xxx");

    if(isset($_GET['hub_mode']) && isset($_GET['hub_challenge']) && isset($_GET['hub_verify_token'])) {
        if($_GET['hub_verify_token']==VERIFY_TOKEN && $_GET['hub_mode']=='subscribe') {
            echo $_GET['hub_challenge'];
        }
    }

    $input = json_decode(file_get_contents('php://input'), true);
    // Get the Senders Graph ID
    $sender = $input['entry'][0]['messaging'][0]['sender']['id'];
    // Get the returned message
    $message = $input['entry'][0]['messaging'][0]['message']['text'];

    error_log($input);
    error_log($sender);
    error_log($message);

the verify phase is fine, but when i send a messagge to my bot in my error_log file I found only empty values:



    [Sun Aug 13 17:35:49.617919 2017] [:error] [pid 22501] [client 173.252.124.11:18834]
    [Sun Aug 13 17:35:49.617951 2017] [:error] [pid 22501] [client 173.252.124.11:18834]
    [Sun Aug 13 17:35:49.617972 2017] [:error] [pid 22501] [client 173.252.124.11:18834]

Here there is also my access_log:



    173.252.124.30 - - [13/Aug/2017:17:35:48 +0200] "POST /webhook HTTP/1.1" 301 3621 "-" "-"
    173.252.124.11 - - [13/Aug/2017:17:35:49 +0200] "GET /webhook/ HTTP/1.1" 200 328 "-" "-"

so why the $input variable is alway empty?

  • 写回答

1条回答 默认 最新

  • doupai8095 2017-08-14 07:29
    关注
    173.252.124.30 - - [13/Aug/2017:17:35:48 +0200] "POST /webhook HTTP/1.1" 301 3621 "-" "-"
    173.252.124.11 - - [13/Aug/2017:17:35:49 +0200] "GET /webhook/ HTTP/1.1" 200 328 "-" "-"
    

    Your server answers the POST request with a 301 redirect, so that the client (Facebook) has to make a GET request next, and therefor you see no more POST data.

    Seeing that the first URL is /webhook, and gets redirected to /webhook/, this is likely just an automatic trailing slash redirect, and should be fixed once you specify the correct URL with the trailing slash in your app settings to begin with.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作