我想展示我的代码,但我不知道为什么我的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"是{"收件人":{" id":" martinxxxxxwang"},"消息":{" text": " 888"}}。 如果我尝试了 " graph.facebook.com/v2.6/me/messages =的access_token令牌"?;, 我被告知""错误":{"消息":"(#100)参数user_id是必需的","类型&#34 ;:" OAuthException"," code":100," fbtrace_id":" FEv3jq / ahEq" "
答案 0 :(得分:1)
问题出在收件人Id中,如果json的任何字段在很多时候都没有,则返回此错误。在您的情况下是收件人ID。