getting notification when someone comments using comments plugin

别等时光非礼了梦想. 提交于 2019-12-04 12:39:25

You can subscribe to comment.create event and send the notification to admin in any way you prefer, once comment is created. Facebook itself doesn't provide such functionality.

This may looks like this (I assume Facebook JavaScript SDK is already loaded on page before doing this, read about it in documentation on Loading, anyway if you're using Social Comments Plugin it should be loaded already):

<script type="text/javascript">
  FB.subscribe('comment.create', function(response){
    // Here you need to do a call to some service/script/application
    // to notify your administrator about new comment.
    // I'll use jQuery ajax to call server-side script to illustrate the flow 
    $.post('//hostnamne/path/to/script', {
      "action": "comment created",
      "url_of_page_comment_leaved_on": response.href,
      "id_of_comment_object": response.commentID
    });
  });
</script>

In your script located at http(s?)://hostnamne/path/to/script you can send a notification to admin, how to do it may vary on way you want it for example if you want to send an email you can use something like this php sample (aging this is just a flow sample, not real code you should use):

 <?
   $admin_email = 'root@localhost';

   $commentID = $_REQUEST['id_of_comment_object'];
   $page_href = $_REQUEST['url_of_page_comment_leaved_on'];
   $message = "comment #{$commentID} was leaved on page {$page_href}";

   mail($admin_email, "You have a new comment", $message);
 ?>

If you need to track the deletion of comments too you can use comment.remove event with similar flow...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!