-2

I have a single fb comment plugin on my page. When someone posts a comment using it, is there a way to get the comment text back?

Thanks to anyone who can help.

Wesley Skeen
  • 7,977
  • 13
  • 42
  • 56
  • You can't do this with only a plugin. You'll have to implement this using some additional code which will be made easier by the use of an SDK... – Lix May 29 '12 at 09:37

2 Answers2

4

Check out the FB.Event.subscribe method in the Facebook Javascript SDK. There is an event called comment.create and with this code you can find the new comment:

FB.Event.subscribe('comment.create', function(post) {
    FB.api({
        method: 'fql.query',
        query: 'SELECT text, post_fbid FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url = "' + post.href + '")'
    }, function(comments) {
        /* Iterate through the all comments for this url */
        for (var i = 0; i < comments.length; i++) {
            /* Find the created comment text by its ID */
            if (comments[i].post_fbid == post.commentID) alert(comments[i].text);
        }
    });
});
CodingHamster
  • 352
  • 2
  • 12
2

You can use Facebook's FQL like this: SELECT text FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url = 'YOUR_COMMENT_URL')

Read more here.

Yan Berk
  • 14,328
  • 9
  • 55
  • 52