我在我的网站上使用<fb:comments>
,但我无法弄清楚如何从具有特定XID的评论框中检索评论计数。
我尝试使用以下代码拦截所有新评论:
FB.Event.subscribe('comments.add', function(response) {
alert("Comment was added.");
});
我从未收到警报。有任何想法吗?我只需要任何给定框的评论数量。
答案 0 :(得分:4)
您可以使用这个简单的fb标记获得评论的计数:
<fb:comments-count href="${url_of_your_page}"></fb:comments-count> Comment
答案 1 :(得分:1)
通过提供带有评论插件的页面的comment_count
,您应该能够通过FQL从link_stat
表获取url
字段。
如果这不起作用,您还可以从xid
表中获取comment
的所有评论,然后自己计算(FQL不支持COUNT
)。但是对于返回的记录数量存在限制,因此很可能只返回前5,000条评论。
答案 2 :(得分:1)
答案 3 :(得分:0)
你问两个不同的问题。 1)如何获得评论计数,以及2)如何使用JavaScript跟踪评论事件。对于2,您需要使用comment标记来包含notify =“true”以便触发事件。
<fb:comments xid="comment_xxx" notify="true"></fb:comments>
答案 4 :(得分:0)
此代码对我有用
<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);
}
});
项目[0] .comments正是您要找的
看一下控制台,你可以看到项目是这样的:
[Object {
id="site url",
shares=65,
comments=87
}]