简体   繁体   中英

Replying to comment with facebook4j

I want to reply a comment of my page's post with facebook4j. Now I can only retrieve replies of comment. I can't reply the comment. I have comment id. What should I do? Does facebook4j support to reply specific comment? Thanks

Either facebook4j or the FB Graph API changed a bit since I last tried this and had it working, so I played with it a bit and found a new solution that works.

First, you'll need to get your Facebook page ID (you can do that here: https://findmyfbid.com/ )

Once you have this, create your post as you currently do, and make sure you capture the return post-id.

String postID = fb.postFeed(your-post-object);

It used to be that the return value was a string like [page-id]_[post-id] , but now it seems to only return [post-id] .

When posting a comment, it expects that first form, so instead of only giving the commentPost() method the post-id, give it both the page- and post-id.

//String commentID = fb.commentPost(postID, your-comment-object);
// ^ this was the old way, which no longer works

String commentID = fb.commentPost(pageID + "_" + postID, your-comment-object);

The return value is in the form [post-id]_[comment-id] . If you now want to go one level further and post replies on that comment, you can use commentPost() again, with the target object being of the form [page-id]_[post-id]_[comment-id] . Since the returned commentID string already contains the post-id, it doesn't need added again here.

String replyID = fb.commentPost(pageID + "_" + commentID, your-reply-object);

The reply object is either a String or a CommentUpdate object, same as with posting a regular comment.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM