我在我的网站上使用<fb:comments>
,但我不知道如何从具有特定XID的评论框中检索评论数。检索在Facebook评论框中的评论数
我试图拦截用下面的代码的所有新评论:
FB.Event.subscribe('comments.add', function(response) { alert("Comment was added."); });
我从未想过收到警报。有任何想法吗?我只需要任何给定框的评论数量。
我在我的网站上使用<fb:comments>
,但我不知道如何从具有特定XID的评论框中检索评论数。检索在Facebook评论框中的评论数
我试图拦截用下面的代码的所有新评论:
FB.Event.subscribe('comments.add', function(response) { alert("Comment was added."); });
我从未想过收到警报。有任何想法吗?我只需要任何给定框的评论数量。
你在问两个不同的问题。 1)如何获得评论数量,以及2)如何使用JavaScript跟踪评论事件。对于2,您需要注释标记才能包含notify =“true”以便触发事件。
<fb:comments xid="comment_xxx" notify="true"></fb:comments>
您应该能够从link_stat
表中通过FQL获得comment_count
字段,通过为您的评论插件提供url
页面。
如果这不起作用,您还可以从comment
表中获得xid
的所有评论,然后自己对其进行计数(FQL不支持COUNT
)。但返回的记录数量有限制,因此很可能只返回前5000条评论。
我还需要在添加新的评论,所以我可以通知网站所有者检测。 – 2010-07-29 04:28:14
你可以得到你的意见计数这个简单的FB标签:
<fb:comments-count href="${url_of_your_page}"></fb:comments-count> Comment
此代码为我工作
<script>
// fb init
window.fbAsyncInit = function() {
FB.init({
appId: 'you app id',
status: true,
cookie: true,
xfbml: true
});
// this event is fired where a comment is created
FB.Event.subscribe('comment.create', function(response) {
alert(response.commentID);
});
};
// im using jquery to make ajax request
$(function(){
$.ajax({
url: "http://graph.facebook.com/?ids=[SITE URL]",
dataType: 'json',
success: function(data){
var items = [];
$.each(data, function(key, val) {
items.push(val)
});
alert(items[0].comments);
console.log(items);
}
});
items [0] .comments是你在找什么
走在控制台中,您可以看到的项目是这样的:
[Object {
id="site url",
shares=65,
comments=87
}]
在世界的哪个地方,你看到提及'notify ='true''属性?甚至没有在他们的文档中提到! – TMC 2011-04-28 03:46:01