PDA

View Full Version : How to get notify when comments are posted by users on a website using Social Plugin?



JLP2073
03-14-2012, 03:50 PM
I have defined a Facebook Application Id and comments are showing up in the Comment Moderation Tool. Still we have to go there to see if a comment was posted or not because I haven't found the way to automate the notification yet.


The comment box is set up that way


In the header



<meta property="fb:app_id" content="my_app_idd"/><meta property="fb:admins" content="101xxxxxx"/>


Before the fb comment



<script>
window.fbAsyncInit = function() {
FB.init({ appId: '338850122832287',
status: true,
cookie: true,
xfbml: true});

FB.Event.subscribe('comment.create',
function(response) {

}
);

};
</script>


And the box



<fb:comments notify="true" href="http://www.xxxxx111.cl/xxxxxxx-50.aspx" num_posts="5" width="730">

What am I missing to get, somehow, notified when a comment is posted ?

JLP2073
03-15-2012, 08:32 AM
Got it working eventually. Not the way I really wanted (that is posting a message on the wall) but sending an email




window.fbAsyncInit = function() {
FB.init({ appId: 'YOU_APP_ID',
status: true,
cookie: true,
xfbml: true});


FB.Event.subscribe('comment.create',
function (response) {
console.log("comment created");
var commentQuery = FB.Data.query("SELECT text, fromid FROM comment WHERE post_fbid='" + response.commentID +
"' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url='" + response.href + "')");
var userQuery = FB.Data.query("SELECT name FROM user WHERE uid in (select fromid from {0})", commentQuery);
FB.Data.waitOn([commentQuery, userQuery], function () {
var commentRow = commentQuery.value[0];
var userRow = userQuery.value[0];
/* console.log(userRow.name + " (id: " + commentRow.fromid + ") posted the comment: " + commentRow.text); */
trackcomments(response['commentID'], response['href'], 'create', commentRow.text, userRow.name, commentRow.fromid);

});
});


};


function trackcomments(_commentid, _address, _action,
_commentMessage, _userName, _userId) {
/* Replace FBComment.aspx by any server script sending the email*/
$.ajax({
type: 'POST',
url: '/FBComment.aspx',
data:
{
commentId: _commentid,
pageUrl: _address,
actionTaken: _action,
userName: _userName,
userId: _userId,
commentMessage: _commentMessage
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
},
success: function (result) {
console.log("successfully received callback");
}
});
}