我如何获得刚刚创建的Facebook评论

时间:2012-05-29 08:49:02

标签: javascript jquery facebook facebook-graph-api facebook-comments

我的页面上有一个fb评论插件。当有人使用它发表评论时,有没有办法获取评论文本?

感谢任何可以提供帮助的人。

2 个答案:

答案 0 :(得分:4)

查看Facebook Javascript SDK中的FB.Event.subscribe方法。有一个名为comment.create的事件,您可以使用此代码找到新评论:

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);
        }
    });
});

答案 1 :(得分:2)

您可以像这样使用Facebook的FQL:SELECT text FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url = 'YOUR_COMMENT_URL')

了解更多here