有人评论使用评论插件时收到通知 [英] getting notification when someone comments using comments plugin

查看:184
本文介绍了有人评论使用评论插件时收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个 iFrame 应用在一个粉丝页面,其中包括评论插件。有没有一种方式我/任何管理员每次有人添加评论时都可以收到通知或电子邮件?

So I have an iFrame app on a fan page, which includes the comments plugin. Is there a way I/any admin can receive a notification or email every time someone adds a comment?

推荐答案

你可以订阅 comment.create 事件,一旦发表评论,就以任何你喜欢的方式将通知发送给管理员。 Facebook本身不提供这样的功能。

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.

这可能看起来像这样(我认为Facebook JavaScript SDK已经在页面上加载之前,请阅读文档,无论如何,如果您使用社会评论插件,它应该已经加载):

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>

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

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...

这篇关于有人评论使用评论插件时收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆