Reputation: 193
I'm trying to catch event when comment is sent. What am I doing wrong? I just want to update every user comment also to facebook group wall and that's why I need to catch the event.
<fb:comments numposts="10" ></fb:comments>
FB.init and event catcher:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'sensored-app-id',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* All the events registered */
FB.Event.subscribe('comments.add', function (response) {
// do something with response
alert("comment added");
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/fi_FI/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
Upvotes: 8
Views: 12115
Reputation: 998
FB.Event.subscribe('comment.create', function(response) {
console.log(response);
});
Upvotes: 5
Reputation: 11
you should note that you have to subscribe for the events after calling FB.init. Works for me now. However, XML Render is having a bug recently
Upvotes: 1
Reputation: 98
You need to add notify="true"
attribute to the fb:comments
tag. Once you add the attribute the comments.add event begin to work.
<fb:comments numposts="10" notify="true"></fb:comments>
or, if you're using the newer html5 compliant tags:
<div class="fb-comments" data-num-posts="10" data-notify="true" ></div>
Upvotes: 5
Reputation: 125
Strangely, if I only have a variable assignment and an ajax post in my comment.create function(response) the event doesn't fire, but if I add a JS alert statement at the bottom or a dud return statement it works?? For example:
FB.Event.subscribe("comment.create", function(response) {
var postData = "page_title='.$safe_page_title.'";
$.ajax({
type: "POST",
url: "/post/post_facebook_comment.php",
data: postData
});
return true;
});
Upvotes: 0
Reputation: 114
You need to be sure to add the notify="true"
tag, and if that doesn't work for you, be sure you are using the latest fbComments plugin. Try adding the migrated="1"
tag as below, and see if this helps:
<fb:comments notify="true" migrated="1"></fb:comments>
Upvotes: 1
Reputation: 896
FB.Event.subscribe('comment.create', function(response) {
FB.api({
method: 'fql.query',
query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE object_id in (select comments_fbid from link_stat where url ='${session.url}') order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text)
}
);
});
Upvotes: 3