当有人使用评论插件评论时收到通知

Mar*_*tor 3 iframe facebook commenting facebook-social-plugins

所以我iFrame在粉丝页面上有一个应用程序,其中包含评论插件.有没有办法我/任何管理员每次有人添加评论时都会收到通知或电子邮件?

Jui*_*ter 10

您可以订阅comment.create事件并发送通知到你喜欢的任何方式联系中,一旦创建注释.Facebook本身不提供此类功能.

这可能看起来像这样(我假设Facebook JavaScript SDK已经在页面上加载了,在关于加载的文档中阅读它,无论如何,如果你正在使用社交评论插件它应该已经加载):

<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>
Run Code Online (Sandbox Code Playgroud)

在您的脚本中,http(s?)://hostnamne/path/to/script您可以向管理员发送通知,如何操作可能会因您想要的方式而有所不同,例如,如果您想发送电子邮件,您可以使用类似这样的php示例(老化这只是一个流量示例,不是你应该使用的真实代码):

 <?
   $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);
 ?>
Run Code Online (Sandbox Code Playgroud)

如果您还需要跟踪评论的删除,您可以使用comment.remove类似流程的事件...