Java Facebook留言者不发送消息
我想显示我的代码,但我不知道为什么我的facebook没有收到这条消息。非常感谢你的帮助Java Facebook留言者不发送消息,java,json,facebook,httpurlconnection,Java,Json,Facebook,Httpurlconnection,我想显示我的代码,但我不知道为什么我的facebook没有收到这条消息。非常感谢你的帮助 HttpURLConnection myConnection = (HttpURLConnection) ((new URL("https://graph.facebook.com/v2.6/me/messages?access_token=the_access_token").openConnection())); myConnection.setDoOutput(true); m
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?访问令牌=令牌”;,
我被告知“error”:{“message”:(#100)参数user_id是必需的”,“type”:“OAuthException”,“code”:100,“fbtrace_id”:“FEv3jq/ahEq”}}}”问题在于接收者id,如果json的任何字段多次不正常,则返回此错误。您的情况是收件人id。您如何获得访问令牌?你有权阅读这个FB页面上的消息吗?@TimBiegeleisen:hi,我在“/developers.facebook.com/apps/(my app)/messenger/”中找到的访问令牌,我已经尝试过了“,我被告知“错误”:{“消息”:(#100)参数user_id是必需的”,“键入”:“OAutheException”,“code”:100,“fbtrace_id”:”FEv3jq/ahEq“}}”,所以我认为toekn没有问题。对于你的问题“你有权阅读来自这个特定FB页面的消息吗?”我想是的,无论如何我不能很好地理解它。我只是偶尔使用Facebook Graph API,但我的建议是首先让调用在Graph explorer中工作,然后担心Java代码。