简体   繁体   English

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

[英]How to list all comments in my domain

I am using the HTML5 version of Facebook Comment in my website. 我在我的网站Facebook Comment使用HTML5版的Facebook Comment I have my own Facebook APP Id. 我有自己的Facebook APP Id。

Using Graph-API , and FQL (I think this is how to do it), I want to list all the Comments posted in my website. 使用Graph-APIFQL (我想这是怎么做的),我想列出我网站上发布的所有评论。

Example - 示例 -

Page Title1
--Comment1
--Comment2
--Comment3

Page Title2
--Comment1
--Comment2
--Comment3

Page Title3
--Comment1
--Comment2
--Comment3

etc.

Please help me out. 请帮帮我。

It is possible, in two different ways, as long as you have a fixed set of sub-pages you want to fetch comments from. 只要您有一组固定的子页面想要从中获取注释,就可以通过两种不同的方式实现。

If you have a large amount of sub-pages, or a variable amount, then you don't have a good scalable solution - and many have been looking for one: 如果您有大量子页面或可变数量,那么您没有一个良好的可扩展解决方案 - 许多人一直在寻找一个:

For a Fixed set of sub-pages in your website, you can either use a batch request, or an FQL query. 对于网站中的一组固定子页面,您可以使用批处理请求或FQL查询。

Batch Request 批量请求


First, you need your access token. 首先,您需要访问令牌。 Just enter the following as a url in a browser (credit to this website ): 只需在浏览器中输入以下内容作为网址(即可归功于网站):

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 FQL


inspired from this post 灵感来自这篇文章

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

Conclusion 结论

Because of this limitation of Facebook, I plan to switch to disqus.com, which apparently supports this feature (As you can see from this blog , for example. (search for 'recent comments') 由于Facebook的这种限制,我计划切换到显然支持此功能的disqus.com(例如,您可以从此博客中看到。(搜索“最近的评论”)

Rather than list all the comments on your site, Facebook wants you to implement code to get notified when a new comment is posted anywhere on your site. Facebook不希望列出您网站上的所有评论,而是希望您实施代码,以便在您网站上的任何位置发布新评论时获得通知。

To make this happen, you have to put some Javascript into the page where the comment is posted to also notify yourself: 要实现这一点,您必须将一些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));
        }); 
    });
};

Where rather than just logging the comment to the console, you would need to implement some AJAX that would send the comment back to your site where you could store the comment in your database, or send yourself an email notifying you that the comment has been posted. 在哪里,而不是仅仅将注释记录到控制台,您需要实现一些AJAX,将评论发送回您的网站,您可以将评论存储在数据库中,或发送电子邮件通知您评论已发布。

Reference: Facebook Comments Plugin 参考: Facebook Comments Plugin

Say your website is http://mywebsite.com/blog.php?id=3 and you have a facebook comments plugin on it, you can access comments this way 假设您的网站是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

Example 1: (Comments plugin installed on developers facebook doc website ) 示例1 :(开发者facebook doc网站上安装的评论插件)

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

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

Example 2: 例2:

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

fetch comments: https://graph.facebook.com/comments/?ids=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-天/

Check this too 检查一下

Sample code for pulling comments can be found on this blog post 可以在此博客文章中找到用于提取评论的示例代码

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

相关问题 使用url获取所有评论的列表? - get list of all comments using url? 如何删除生产分支中的所有评论 - how to remove all comments in production branch 如何计算同一帖子中的所有评论? - How to count all comments that are in the same individual post? 如何使用javascript将rel =“ nofollow”添加到与我的域不相关的所有外部链接? - How to add rel=“nofollow” to all external links that do not related to my domain with javascript? 如何将JWT设置为存储在本地存储中,以便我的域的所有部分都可以访问它? - How do set JWT to be store in local storage so all parts of my domain can access it? 如何使用Angular 5验证我的带复选框列表是否全部选中 - How to verify if my list with checkbox are all checked using Angular 5 如何列出节点 js 脚本中的所有函数? - How can I list all the functions in my node js script? 新手问题:如何在我的网络应用程序中维护所有用户的数据列表? - Newb question: How to maintain a data list for all users in my webapp? 如何列出我的机器人所在的所有公会及其各自的 ID - How do I list all guilds my bot is in with their respective ids 如何从Facebook组获取我所有帖子的列表 - How to get a list of all my posts from the Facebook group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM