[英]How to list all comments in my domain
我在我的網站Facebook Comment
使用HTML5版的Facebook Comment
。 我有自己的Facebook APP Id。
使用Graph-API
和FQL
(我想這是怎么做的),我想列出我網站上發布的所有評論。
示例 -
Page Title1
--Comment1
--Comment2
--Comment3
Page Title2
--Comment1
--Comment2
--Comment3
Page Title3
--Comment1
--Comment2
--Comment3
etc.
請幫幫我。
只要您有一組固定的子頁面想要從中獲取注釋,就可以通過兩種不同的方式實現。
如果您有大量子頁面或可變數量,那么您沒有一個良好的可擴展解決方案 - 許多人一直在尋找一個:
對於網站中的一組固定子頁面,您可以使用批處理請求或FQL查詢。
批量請求
首先,您需要訪問令牌。 只需在瀏覽器中輸入以下內容作為網址(即可歸功於此網站):
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,將評論發送回您的網站,您可以將評論存儲在數據庫中,或發送電子郵件通知您評論已發布。
假設您的網站是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.