I am using Facebook comment box plugin:
<fb:comments href="${myPageUrl}" num_开发者_StackOverflow社区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.
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.
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!
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 )
});
});
精彩评论