Bounce
Bounce

Reputation: 2095

Notify facebook application admin when comments are posted using social plugin

Is it possible to send notification to facebook application admins when comments are posted using facebook social comments plugin?

Comment plugin is set up this way:

<meta property="fb:admins" content="111,222,333" />
<meta property="fb:app_id" content="123456789" />

<div id="fb-root"></div>
<script>
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=123456789";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>

<div class="fb-comments" data-href="http://example.com" data-num-posts="2" data-width="470" notify="true"></div>

<script>
    window.fbAsyncInit = function(){ 
             FB.Event.subscribe('comment.create', function(response){
                   alert(response); 
             });
    };
</script>

Event subscribe works pretty good in this example(shows response alert), but is it possible to send notification to application administrators?

Your help would be appreciated.

Upvotes: 6

Views: 3117

Answers (1)

Liam
Liam

Reputation: 20950

I set up a simple PHP script to email me whenever a comment is posted. The PHP is like this:

<?php
mail('[email protected]','facebook_notification.php',
'Comment activity on http://example.com'.$_GET['path']);

and this JavaScript passes the URL of the comment page to the PHP script:

FB.Event.subscribe('comment.create', function(response){
var dummyImage = new Image;
dummyImage.src = 'http://example.com/facebook_notification.php?path='+response.href.replace('http://','');
});

I can easily add more addresses if I need to.

Upvotes: 5

Related Questions