简体   繁体   English

Facebook 消息器不发送消息

[英]Facebook messager not send message

I would like to show my codes but I do not know why my facebook has not got the message.我想显示我的代码,但我不知道为什么我的 facebook 没有收到消息。 Thank you very much for help非常感谢您的帮助

    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();

By the way, the content of "myTest" is {"recipient":{"id":"martinxxxxxwang"},"message":{"text":"888"}}.顺便说一下,“myTest”的内容是{"recipient":{"id":"martinxxxxxwang"},"message":{"text":"888"}}。 And if i try如果我尝试
"graph.facebook.com/v2.6/me/messages?access_token=token"‌​;, I was told ""error": { "message": "(#100) The parameter user_id is required", "type": "OAuthException", "code": 100, "fbtrace_id": "FEv3jq/ahEq" } }" "graph.facebook.com/v2.6/me/messages?access_token=token"‌ ;, 我被告知 ""error": { "message": "(#100) 参数 user_id 是必需的", "type ": "OAuthException", "code": 100, "fbtrace_id": "FEv3jq/ahEq" } }"

The problem is in the recipient Id, if any field of the json not is OK in many times return this error.问题出在收件人 ID 上,如果 json 的任何字段不是 OK 多次返回此错误。 In your case is the recipient id.在您的情况下是收件人 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM