Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook comment ID issue

I am using FBML's fb:comments plugin on a Facebook app (which, although it's described as "legacy" on the Facebook developer site, seems to be the only way to get proper Facebook comment integration on a Canvas app? Please let me know if I'm wrong, it seems navigating the open ocean is easier than navigating the Facebook documentation). I'm also using the JavaScript SDK to subscribe to the comment.create event so I can keep track of who is commenting on my pages. Easy enough, and this seems to work to an extent, but while I have the following code:

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

This returns a nice JSON object including the following nugget:

commentID: "10150576473610309"

Great! I have a comment ID. So now I go to the Facebook graph API to get a bit more information about this comment (I want the text, author, etc.), so I issue the following in PHP because, according to the Facebook docs, everything on Facebook has a unique ID, and just hitting up the Graph API with this ID will give you some sweet info.

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

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

"id": "10150576473610309_20003210"

What is this additional underscore and number?! Calling the graph API with this comment ID gives me the comment info! Where and how (and why?) did this new ID come about? (Of course I tried the Facebook dev forum but it seems asking my mouse the same question would have achieved similar results).

like image 524
jackbot Avatar asked Apr 20 '11 12:04

jackbot


People also ask

Why is Facebook not showing my comments?

In many cases, refreshing the Facebook app solves the issue as sometimes the native app gets stuck. You can try refreshing the app by swiping down on your smartphone. This will refresh your feed, comments, and posts, after which you can try accessing the comments.

Why is Facebook Comments not working?

One of the common reasons behind Facebook comments fails to load is a poor network connection. Thus, you need to make sure that you are using reliable and strong Wi-Fi or cellular internet connection to load your Facebook comments. You can visit other pages to check if other ones load with the same connection.

Why can't I comment on someone's Facebook live?

The broadcaster of a live video has the ability to apply comment moderation settings that may limit a viewer's ability to comment on their live video. In some cases, you may see one of the notifications below explaining why your comment was limited or blocked.

How do I find my comment_ID on Facebook?

However, it could also be attributed to a photo, an activity - just about any type of Facebook object. When you’re on this linked page, check your address bar. You’re looking for something that says “ comment_id=…” The number after the equal sign ( = ) is your comment_id.

How to fix “please confirm your identity” on Facebook?

To fix “Please Confirm Your Identity” on Facebook, you need to take and upload a photo of your ID. Then, enter an email address that is not linked to your Facebook account. Lastly, Facebook will send you a link to regain access to your account. Tap on the link to regain access to your account.

Why do developers need the Facebook post_ID or comment_ID?

Typically, developers need the facebook post_id or comment_id. In this post, I’ll show you how to quickly identify these IDs when troubleshooting. Posts are items that appear in a Facebook timeline that are created by that timeline’s owner, and aren’t responding to anything.

How do I retrieve a comment_ID from a post?

The process for retrieving a comment_id is very similar to that of a post_id - first, click the timestamp at the bottom of the comment. This will take you to the page of the object the comment was on. In this example, it was my original post.


2 Answers

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

Thanks to Jonathan & Tarmo I developped a mixed approch :

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 get all the info needed on the last comment posted.

PS: there is a field named 'username' in the table comment ( http://developers.facebook.com/docs/reference/fql/comment/ ) but it doesn't really seem to work (it says username "Anonymous user" when it isn't anonymous... that's why I used the second query to get the user info)

like image 98
Olivier Avatar answered Sep 26 '22 03:09

Olivier


This is now the preferred way to get the comments from a comment box:

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

Anyway, about your question. I've found that facebook adds an id whenever they launch a new platform. For example, the id of an object for FQL, graph api, and old REST API are all different. To see this in action look at a photo in an album. All those ids separated by an underscore are: The graph api id, the FQL aid, the photo graph api unique id, and some additional ids are possible, depending on who uploaded it. Those mysterious numbers that get added after your comments are just some kind of comment counter for your application, or a group of applications, basically useless.

So, from my experience mixing facebook platforms is always a bad idea, involving a lot of experimentation and hacks. If it's possible always use a singe platform, the graph api is the best bet right now.

like image 25
DannyKK Avatar answered Sep 22 '22 03:09

DannyKK