Facebook Comments Comment Plugin

I am using the Facebook comments plugin:

<fb:comments href="${myPageUrl}" num_posts="20" width="630"></fb:comments>

      

Everything works fine. The problem is I want to keep the comment posted to my database. Is there a way to get the text posted in the comment box.

I am using the following js to catch the event comment-create

.

FB.Event.subscribe('comment.create', function(response) {        
        alert(response.commentID)
});

      

I am getting from this commentId

, but I don't know how to get the exact comment posted on a specific event comment-create

.

+1


source to share


3 answers


Coomie: Actually, whenever a comment is posted, I will catch the event via "comment.create". I was able to catch the event, but I was wondering how to get the comment (text) posted on that particular event. Like event.text or event.comment but no direct method found

So now I am manipulating it with fql. Which is somewhat similar to your example. You will get the whole list first and then select the top one. My example code is below:



FB.Event.subscribe('comment.create', function(response) {
      FB.api({
        method: 'fql.query',
        query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE  object_id in (select comments_fbid from link_stat where url ='${PageUrl}') order by time desc limit 1"
      },
      function(response) {
        var feed = response[0];          
        alert(feed.text)
      });
});  

      

So this method gives me exactly the same result that I want.

+2


source


I don't have a complete answer, but this should help you.

You can use the facebook api graphics to retrieve the public graph id information (open graph id is the FB way of identifying a person, website, app or url). For example. this page: http://www.inhousegroup.com.au/newsroom/23-best-practice-for-advanced-seo/ (the place fired me) uses the comment field. The webpage has a public id 10150441190653416. So when you comment on this page, facebook sees your comment as a wall post on that wall page.

Using graph api you can get JSON information about the page here: Http: /graph.facebook.com/10150441190653416

And you can get posts from this address: http://graph.facebook.com/10150441190653416/posts



But you will need to get an access token.

Then you just need to import the messages to save and compare your db's to JSON and add records as needed.

Good luck!

+1


source


FB.Event.subscribe('comment.create', function(response) {
  var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
  FB.Data.waitOn([commentQuery], function () {
    text = commentQuery.value[0].text;
    // Use your preferred way to inform the server to save comment
    $.post( 'http://example.com/comment', text )
  });
});

      

+1


source







All Articles