Facebook Messenger 不发送消息

Facebook messager not send message

我想显示我的代码,但我不知道为什么我的 facebook 没有收到消息。非常感谢您的帮助

    HttpURLConnection myConnection = (HttpURLConnection) ((new URL("https://graph.facebook.com/v2.6/me/messages?access_token=the_access_token").openConnection()));
    myConnection.setDoOutput(true);
    myConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    myConnection.setRequestProperty("Accept", "application/json");      
    myConnection.setRequestMethod("POST");
    myConnection.connect(); 
  JSONObject myTest = new JSONObject();

        try {
            JSONObject recipient = new JSONObject();
            recipient.put("id", "martinxxxxxwang");         
            myTest.put("recipient", recipient);
            JSONObject message = new JSONObject();
            message.put("text", "888");         
            myTest.put("message", message);     
            response.getWriter().append(myTest.toString());             

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       
        OutputStream os = myConnection.getOutputStream();
        os.write(myTest.toString().getBytes("UTF-8"));
        os.close();

对了,"myTest"的内容是{"recipient":{"id":"martinxxxxxwang"},"message":{"text":“888”}}。 如果我尝试
"graph.facebook.com/v2.6/me/messages?access_token=token"‌ ;, 我被告知“"error": { "message": “(#100) 参数 user_id 是必需的”, "type": "OAuthException", "code" : 100, "fbtrace_id": "FEv3jq/ahEq" } }"

问题出在recipient Id,如果json的任何一个字段都不是OK多次return这个错误。在您的情况下是收件人 ID。