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 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题