Get comments from Facebook-like?

I have a Facebook application that has its own messaging system, but I still want to show the comments that users made on Facebook from user sections or like.

Let's say that the URL (for example, http://myapp.com/?myId=100005235 ) is used on Facebook, and users add comments to the resource. Such comments (and username) are what I would like to receive.

Can I do this using facebook-js-sdk?

+4
source share
2 answers

Yes, you can. The easiest way is to make a FQL call to Facebook. You should also do this by calling the Graph API, but in my testing, I could not find a way to return the data you need.

In FQL, you need to query three different tables: link_stat to get the Facebook ID for your URL, comments to get information about comments, and user to get the name of registered users who left a comment.

The following is a polygon expandable for readability.

 { "my_link": "SELECT comments_fbid, comment_count, normalized_url FROM link_stat WHERE url ='http://funcook.com/receta.php?id=53' ", "comment": "SELECT object_id, fromid, time, text, username FROM comment WHERE object_id IN (SELECT comments_fbid FROM #my_link)", "com_users": "SELECT name, uid FROM user WHERE uid IN (SELECT fromid FROM #comment)" } 

You will get a JSON object. With a few test urls on my sites, I found that my_link.comment_count not always equal to count(comment) . I found cases when one of them shows zero, and the other does not.

Here it is in the script:

 <script> FB.api( '/fql', {q:{"my_link":"SELECT comments_fbid, comment_count, normalized_url FROM link_stat WHERE url='http://funcook.com/receta.php?id=53'", "comment":"SELECT object_id, fromid, time, text, username FROM comment WHERE object_id IN (SELECT comments_fbid FROM #my_link)", "com_users": "SELECT name, uid FROM user WHERE uid IN (SELECT fromid FROM #comment)" }}, function(response){ console.log(response) }); </script> 
+2
source

Here is the Graph API link for comments and posts , the latter says that each post has a comments object.

I have never used the Graph API before, and I am not able to write code from above, so I cannot provide you with real code, but maybe something like this:

 FB.api( '/19292868552_10150189643478553', // fetch a post by its id function(response) { // callback function for (var comment in response["comments"]["data"]) { // process comment } } ); 

Although it might make more sense to get comments on the server side - depending on what makes more sense in your use case.

0
source

All Articles