【问题标题】:Facebook comment box pluginFacebook评论框插件
【发布时间】:2012-04-09 12:02:45
【问题描述】:

我正在使用 Facebook 评论框插件:

<fb:comments href="${myPageUrl}" num_posts="20" width="630"></fb:comments>

一切正常。问题是我想将发布的评论存储到我的数据库中。有什么方法可以获取评论框中发布的文本。

我正在使用下面的js来捕捉comment-create事件。

FB.Event.subscribe('comment.create', function(response) {        
        alert(response.commentID)
});

我从中得到了一些commentId,但我不知道如何获取针对特定comment-create 事件发布的确切评论。

【问题讨论】:

  • 是的,我已经解决了。但我不确定这是否是最好的方法....我的意思是我已经按时间对所有 cmets 进行了排序,并采用了最新的一个并假设,正如发布的那样。

标签: facebook facebook-comments


【解决方案1】:

Coomie:实际上,每当发布评论时,我都会通过“comment.create”来捕捉事件。我能够赶上该事件,但我想知道如何获取在该特定事件上发布的评论(文本)。类似 event.text 或 event.comment 但没有找到直接方法

所以,现在我用 fql 来操作它。这与您的示例有些相似。首先检索整个列表,然后选择最上面的一个。 我的示例代码如下:

FB.Event.subscribe('comment.create', function(response) {
      FB.api({
        method: 'fql.query',
        query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE  object_id in (select comments_fbid from link_stat where url ='${PageUrl}') order by time desc limit 1"
      },
      function(response) {
        var feed = response[0];          
        alert(feed.text)
      });
});  

所以这个方法给了我想要的结果。

【讨论】:

    【解决方案2】:

    我没有完整的答案,但这应该可以帮助你。

    您可以使用 facebook graph api 提取有关开放图 id 的信息(开放图 id 是 FB 识别人员、网站、应用程序或 URL 的方式)。例如。这一页: http://www.inhousegroup.com.au/newsroom/23-best-practice-for-advanced-seo/(解雇我的地方) 使用评论框。该网页的开放 ID 为 10150441190653416。因此,当您在此页面上发表评论时,facebook 会将您的评论视为该页面“墙上”的墙上帖子。

    使用图形 API,您可以在此处获取有关页面的一些 JSON 信息: http://graph.facebook.com/10150441190653416

    你可以从这个地址获取帖子: http://graph.facebook.com/10150441190653416/posts

    但您必须获得访问令牌。

    然后您只需在保存时导入帖子并将您的数据库与 JSON 进行比较并根据需要添加记录。

    祝你好运!

    【讨论】:

      【解决方案3】:
      FB.Event.subscribe('comment.create', function(response) {
        var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
        FB.Data.waitOn([commentQuery], function () {
          text = commentQuery.value[0].text;
          // Use your preferred way to inform the server to save comment
          $.post( 'http://example.com/comment', text )
        });
      });
      

      【讨论】:

        猜你喜欢
        • 2011-12-18
        • 1970-01-01
        • 1970-01-01
        • 2012-10-11
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        • 2012-09-30
        • 1970-01-01
        相关资源
        最近更新 更多