【问题标题】:Facebook messager not send messageFacebook 信使不发送消息
【发布时间】:2017-02-19 00:40:14
【问题描述】:

我想显示我的代码,但我不知道为什么我的 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) The parameter user_id is required", "type": "OAuthException", "code": 100, "fbtrace_id": "FEv3jq/ahEq" } } "

【问题讨论】:

  • 您是如何获得访问令牌的?您是否有权阅读来自此特定 FB 页面的消息?
  • @TimBiegeleisen:嗨,我在“/developers.facebook.com/apps/(my app)/messenger/”中获得的访问令牌,我试过“graph.facebook.com/v2.6/me/messages?access_token=token”,我被告知 ""error": { "message": "(#100) The parameter user_id is required", "type": "OAuthException", "code": 100, "fbtrace_id": "FEv3jq/ahEq" } } “所以我认为toekn没有问题。对于您的问题“您是否有权阅读来自此特定 FB 页面的消息?”我想是的,反正我不能很好地理解它。
  • 我只偶尔使用过 Facebook Graph API,但我的建议是首先让调用在 Graph 浏览器中工作,然后再考虑你的 Java 代码。

标签: java json facebook httpurlconnection


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 2016-08-11
    • 2013-10-28
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多