Facebook comment box plugin

一曲冷凌霜 提交于 2019-12-02 08:32:05

问题


I am using Facebook comment box plugin:

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

Every thing is working fine. The problem is that I want to store the comment posted into my database. Is there any way to fetch the text posted on the comment box.

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

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

I'm getting some commentId from this but I don't know how to fetch the exact comment posted on a particular comment-create event.


回答1:


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

So, now I am manipulating it with fql. Which is somewhat similar to you example. First retrieving the whole list and then selecting the top one. My sample 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 is giving me exactly the same result I want.




回答2:


I don't have the complete answer but this should get you on your way.

You can use the facebook graph api to extract information about an open graph id (an open graph id is FB's way of identifying a person, website, application or URL). Eg. this page: http://www.inhousegroup.com.au/newsroom/23-best-practice-for-advanced-seo/ (the place that fired me) uses a comment box. The web page has an open id of 10150441190653416. So when you comment on this page facebook sees your comment as a wall post on that page's "wall".

Using the graph api, you can get some JSON info about the page here: http:/graph.facebook.com/10150441190653416

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

But you'll have to get an access token.

Then you just have to import the posts on save and compare your db to the JSON and add records as neccessary.

Good luck!




回答3:


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 )
  });
});


来源:https://stackoverflow.com/questions/5551197/facebook-comment-box-plugin

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