Problem with comments on Facebook comments

I use the FBML fb: comments plugin in the Facebook application (which, although it was described as a “legacy” on the Facebook developer site, seems to be the only way to get the Facebook comments integrated in the Canvas application correctly? I know if I am mistaken, it seems to open open the ocean is easier than navigating the documentation on Facebook). I also use the JavaScript SDK to subscribe to the comment.create event comment.create that I can keep track of who is commenting on my pages. Easy enough, and this seems to work to some degree, but so far I have the following code:

  FB.Event.subscribe('comment.create', function(response) { console.log(response); }); 

This returns a good JSON object, including the following nugget:

 commentID: "10150576473610309" 

Fine! I have a comment id. So, now I go to the Facebook API to get a little more information about this comment (I want text, author, etc.), So I set out the following in PHP, because according to Facebook docs, everything on Facebook has a unique identifier, and simply by clicking on the Graph API with that identifier, you will get some sweet information.

 file_get_contents('http://graph.facebook.com/10150576473610309'); 

Oh no! This returns false. This is strange. Therefore, I check the API for all comments related to a specific page, and this gives me a list of comments ... but the identifier of the one I just added is different, now it is in the format:

 "id": "10150576473610309_20003210" 

What is this extra character and number ?! Calling the graphical API with this comment gives me information about the comments! Where and how (and why?) Did this new identifier appear? (Of course, I tried the forum for Facebook developers, but it seems that my question coincides with the same question as similar results).

+7
source share
7 answers

Now this is the preferred way to get comments from the comments window:

http://developers.facebook.com/blog/post/490

Anyway, about your question. I found that facebook adds an identifier whenever it launches a new platform. For example, the object identifier for FQL, the api chart, and the old REST API are all different. To see this in action, look at the photo in the album. All these identifiers, separated by an underscore, are: api id of the chart, FQL help, graphical api unique identifier, as well as some additional identifiers, depending on who downloaded them. Those mysterious numbers that are added after your comments are just a kind of comment counter for your application or a group of applications that are mostly useless.

So, in my experience, mixing facebook platforms is always bad, including a lot of experimentation and hacks. If possible, always use a single platform, an api chart is the best bet right now.

+4
source

Edit 06/13/2014: Be careful, the username field is now out of date (thanks @ Cyril-n)

Thanks to Jonathan and Tarmo, I developed a mixed approach:

 FB.Event.subscribe('comment.create', function(response) { var commentQuery = FB.Data.query("SELECT text, fromid FROM comment WHERE post_fbid='"+response.commentID+"' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url='"+response.href+"')"); var userQuery = FB.Data.query("SELECT name FROM user WHERE uid in (select fromid from {0})", commentQuery); FB.Data.waitOn([commentQuery, userQuery], function() { var commentRow = commentQuery.value[0]; var userRow = userQuery.value[0]; console.log(userRow.name+" (id: "+commentRow.fromid+") posted the comment: "+commentRow.text); }); } ); 

With this, you will get all the information needed for the last published comment.

PS: in the commentary on the table there is a field named 'username' ( http://developers.facebook.com/docs/reference/fql/comment/ ), but in fact it doesn’t look like (he says the username is “Anonymous user” when it is not anonymous ... why did I use the second request to get user information)

+7
source

If you just need to request the body of the comment and the author, then you can use the FQL api. You need to request comment tables and link_stat.

 SELECT text, fromid FROM comment WHERE post_fbid=#{commentID} AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url="#{href}") 

The commentID and href variables should be available to you from the comment.create callback.

+3
source

Faced the same problem! These numbers look like a time stamp, or so ...

Nothing about this at http://developers.facebook.com/docs/reference/api/Comment/

You can take some recent comments for the event page (the limit as described at http://developers.facebook.com/docs/reference/api/ ), but as a temporary workaround.

So, I am also looking for a solution.

0
source

Solved this with an ugly and fragile hack, but it works. Here are the basic steps:

  • subscribe to comment.create
  • download the list of comments from '/ comments /? ids = PAGE_URL & limit = 10000 '
  • make the last comment and assume that it is correct.

Code example :

 FB.Event.subscribe('comment.create', function() { var href = document.location.href; FB.api('/comments/?ids=%s&limit=1000'.format(href), function(comments) { if (comments[href] && comments[href].data) { var comment = _(comments[href].data).last(); jQuery.post('/events/comment', { comment_id : comment.id, message : comment.message }); } }); }); 

This is a race condition that many users can comment on at the same time, and things are likely to be mixed up.

Another possible problem might be paging comments, I hope the limit of 10000 makes it not print for a while.

The third problem is that this list can be huge and may take some time to load.

This example uses jQuery and Underscore.js in addition to the Facebook JS SDK.

0
source

The voted answer simply refers to the way the api chart is used to get all the comments on the page. The same problem remains, you don’t know what the comment is for the last comment.

My main model was to solve it on the server side - after creating a comment on the server side, I retrieve all the comments for the page, then check any comment identifiers that were not saved and are stored. However, I don’t have to directly associate user action with this.

0
source

Olivier’s answer is very elegant and complete, but I find it too involutive. How stupid, since it is on the facebook side, to give a json response object where the value “commentID” has nothing to do with the real link, since the last element of the “data” array in the api graph response is the newest comment, then you can just get in PHP the last element with the end () function in the "data" subarray in the JSON response.

EDIT: Secondly, Olivier's approach is wonderful because it allows you to create a permalink from the commentID value. By selecting the "id" field for comments and ignoring everything else, you have a mutable code that is contained in the permalink URL in the form of "id_comments_fbid".

EDIT: The Olivier method does not initiate responses to existing comments, as they are addressed by selecting "comments" rather than the specified request.

0
source

All Articles