admin管理员组文章数量:1122832
I have a task that I need to send a comment from the user to the fan page, for this I wrote the sendComment method
public void sendComment(String postId, String message) throws Exception{
String endpoint = ".0/" + postId + "/comments";
String body = "message=" + URLEncoder.encode(message, StandardCharsets.UTF_8)
+ "&access_token=" + EAAGNO4a7r2wBO3zL....;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endpoint))
.POST(HttpRequest.BodyPublishers.ofString(body))
.header("Content-Type", "application/x-www-form-urlencoded")
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
System.out.println("Comment published: " + response.body());
} else {
System.err.println("Failed to publish comment. Response Code: " + response.statusCode());
System.err.println("Response Body: " + response.body());
}
}
if you are using this method to post comments from fan page to fan page then in theory it should work, but if from a user to a fan page it won’t work
when I used the method above using the post id and token of the user from which the comment should be posted then i got this error
Failed to publish comment. Response Code: 400 Response Body: {"error":{"message":"Invalid request.","type":"OAuthException","code":1,"fbtrace_id":"A1rMqwYGGdAl0G4MkBZxfBT"}}
but when i use Graph API Explorer with the same data then the request passes
本文标签: facebookHow to send comments from user to fan page via Java using Graph APIStack Overflow
版权声明:本文标题:facebook - How to send comments from user to fan page via Java using Graph API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284015a1927158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论