Facebook messager不发送消息

问题描述:

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

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” 的内容为{ “收件人”:{ “ID”: “martinxxxxxwang”}, “消息”:{ “文”:“888 “}}。 如果我尝试
“graph.facebook.com/v2.6/me/messages?access_token=token";, 我被告知”“错误”:{“message”:“(#100)The参数user_id是需要 “ ”类型“: ”OAuthException“, ”代码“:100, ”fbtrace_id“: ”FEv3jq/ahEq“}}”

+0

你是如何获得访问令牌的?你有权从这个特定的FB页面读取消息吗? –

+0

@TimBiegeleisen:嗨,我在“/developers.facebook.com/apps/(my app)/ messenger /”中获得的访问令牌,我试过了“https://graph.facebook.com/v2”。 6/me/messages?access_token = token“,我被告知”“错误”:{ “消息”:“(#100)参数user_id是必需的”, “type”:“OAuthException”, “code” :100, “fbtrace_id”:“FEv3jq/ahEq” } }“所以我认为toekn是没有问题的。对于你的问题“你有权从这个特定的FB页面读取消息吗?”我认为,无论如何,我无法理解它。 – martinwang1985

+0

我只能偶尔使用Facebook Graph API,但我的建议是首先在Graph Explorer中调用工作,然后担心Java代码。 –

的问题是在接收者ID,如果JSON的任何场不是很多次都可以返回这个错误。你的情况是收件人ID。

+0

好的,非常感谢你 – martinwang1985