繁体   English   中英

如何列出我的域中的所有评论

[英]How to list all comments in my domain

我在我的网站Facebook Comment使用HTML5版的Facebook Comment 我有自己的Facebook APP Id。

使用Graph-APIFQL (我想这是怎么做的),我想列出我网站上发布的所有评论。

示例 -

Page Title1
--Comment1
--Comment2
--Comment3

Page Title2
--Comment1
--Comment2
--Comment3

Page Title3
--Comment1
--Comment2
--Comment3

etc.

请帮帮我。

只要您有一组固定的子页面想要从中获取注释,就可以通过两种不同的方式实现。

如果您有大量子页面或可变数量,那么您没有一个良好的可扩展解决方案 - 许多人一直在寻找一个:

对于网站中的一组固定子页面,您可以使用批处理请求或FQL查询。

批量请求


首先,您需要访问令牌。 只需在浏览器中输入以下内容作为网址(即可归功于网站):

https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APP_ID&client_secret=APP_SECRET

And this is the javascript jquery code to make a batch request to fetch comments from several urls at once:

$.ajax({ url: 'https://graph.facebook.com/', type : "POST", data: { access_token : 'YOUR_APP_ACCESS_TOKEN', batch : '[ \ {"method":"GET","relative_url":"URL1"}, \ {"method":"GET","relative_url":"URL2"} \ ]' }, success: function(data) { jdata = JSON.parse(data); $.each(jdata, function(index,value){ jdata[index].body = JSON.parse(value.body); console.log(value.body); }); // Do whatever you want with jdata } }); 

FQL


灵感来自这篇文章

FB.api({
    method: 'fql.query',
    query: 'select text from comment where object_id in (select comments_fbid from link_stat where url="URL1" or url="URL2")'
  }, function(response) {
    // Do something with results
  });

结论

由于Facebook的这种限制,我计划切换到显然支持此功能的disqus.com(例如,您可以从此博客中看到。(搜索“最近的评论”)

Facebook不希望列出您网站上的所有评论,而是希望您实施代码,以便在您网站上的任何位置发布新评论时获得通知。

要实现这一点,您必须将一些Javascript放入发布评论的页面中,以便通知您自己:

window.fbAsyncInit = function(){
    console.log("subscribing to comment create");
    FB.Event.subscribe('comment.create',function(response){
        console.log("facbeook comment created: " + JSON.stringify(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 () {
            console.log("Facebook comment: " + JSON.stringify(commentQuery));
        }); 
    });
};

在哪里,而不是仅仅将注释记录到控制台,您需要实现一些AJAX,将评论发送回您的网站,您可以将评论存储在数据库中,或发送电子邮件通知您评论已发布。

参考: Facebook Comments Plugin

假设您的网站是http://mywebsite.com/blog.php?id=3并且您有一个Facebook评论插件,您可以通过这种方式访问​​评论

 https://graph.facebook.com/comments/?ids={YOUR_URL}.

{YOUR_URL} becomes http://mywebsite.com/blog.php?id=3

示例1 :(开发者facebook doc网站上安装的评论插件)

网站: http//developers.facebook.com/docs/reference/plugins/comments

获取评论: https//graph.facebook.com/comments/?aid = http://developers.facebook.com/docs/reference/plugins/comments

例2:

网站: http//techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/

获取评论: https//graph.facebook.com/comments/?aid = http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-天/

检查一下

可以在此博客文章中找到用于提取评论的示例代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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