Got it working eventually. Not the way I really wanted (that is posting a message on the wall) but sending an email
Code:
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");
}
});
}