首页 文章

Facebook Messenger bot错误:参数收件人是必需的

提问于
浏览
5

我用来连接机器人的bash命令是:curl -ik -X POST'https://graph.facebook.com/v2.6/me/messages?access_token=#AccessToken'

我的错误信息是:

{"error":{"message":"(#100) The parameter recipient is required","type":"OAuthException","code":100,"fbtrace_id":"EFqWAGq2ABs"}}

有人怎么解决它?

7 回答

  • 0

    万一有人错过了这个,我在意外使用错误的内容类型时遇到了这个问题 - 我使用的是 application/x-www-form-urlencoded 而不是 application/json

    所以我的建议是,

    • 检查您是否确实传递了参数

    • 仔细检查字符和编码

    • 确保使用正确的 endpoints

    • 并确保在发布JSON请求时使用正确的内容类型 .

  • 1

    请使用"thread_settings" endpoints “https://graph.facebook.com/v2.6/me/thread_settings”作为API endpoints .

    您正在使用消息 endpoints .

  • 4

    它归结为机器人的逻辑 . 我最近也遇到了这个错误,我花了几天时间来调试它 . 对我来说问题是我在编译 messageData 对象的函数之外调用了 callSendAPI(messageData) 方法 .

    显然,在编译它的函数之外传递 messageData 会发送一个空对象而不是已编译的对象 . 因此错误消息 (#100) The parameter recipient is required . 仅仅因为空对象没有定义任何 receipientId .

    请检查你的代码的逻辑,以确保你没有做出与我相同的错误 . 希望这有助于:)快乐的编程 .

  • 0

    endpoints 是错误的 . 而不是 https://graph.facebook.com/v2.6/me/messages?access_token=#AccessToken ,使用此 endpoints

    https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>

    当我们不阅读文档时会发生这种情况 . 信息就在这里https://developers.facebook.com/docs/messenger-platform/discovery/welcome-screen#,就在 "Setting the Get Started Button Postback" 下面 .

  • 1

    您需要发送收件人ID参数 . 尝试:

    curl -X POST -H "Content-Type: application/json" -d '{ "recipient":{"id":"YOUR RECIPIENT ID" }, "message":{ "text":"hello from bot" }}' "https://graph.facebook.com/v2.6/me/messages?access_token=YOUR_ACCESSTOKEN"
    

    最好的祝福 .

  • 0

    当您的代码中出现错误(语法或逻辑错误)时,也可能会发生此问题 . 在我的情况下,我在 webhook.php 的代码中有这部分(这是我在Facebook注册的回调页面)

    $message = $input['entry'][0]['messaging'][0]['message']['text'];
    
    "message":{
        "text":"Sorry, we currently do not have an article related to "'.$message.'"."
        }
    

    当我注册https://domain.com/webhook.php作为回调时,它将不会收到任何 $message ,因此它会导致错误并且不接受我的回调网址 .

    检查您的代码,确保您只回应挑战 .

    $challenge = $_REQUEST['hub_challenge'];
    $verify_token = $_REQUEST['hub_verify_token'];
    
    if ($verify_token === 'verify_token') {
        echo $challenge;
    }
    
  • 1

    此错误消息还有另一个原因:当您发送错误字符(如a -tab-)时,Facebook也会返回此错误,因此请检查特殊字符上的返回文本 .

相关问题