Arrow

Exporting Facebook comments from Comments Box using xid and migrated=1

First published on June 20, 2013

If you’ve been using the Facebook Comments Box on your website for a few years, you might have gone through a migration in 2011 where you simply added a “migrated=1″ parameter as suggested by Facebook:

<fb:comments xid="[id_of_page]" migrated="1"></fb:comments>

As of July 10, 2013 they are completely dropping support for the “xid” parameter and requiring an “href” parameter. However, this means that if you “migrated” your comments in 2011, you are in danger of losing all existing comments. The Facebook documentation is silent on this issue and it seems like others are facing the same problem without a known solution. This was enough to finally move one of Mugo‘s clients away from Facebook comments (and specifically to Disqus).

Of course, moving away from Facebook comments means that you need a way to export your existing comments. This is possible with some guesswork, since the documentation doesn’t mention some legacy fields like “xid”, which are crucial to the export. I won’t go through the entire process of using the Facebook Graph API and FQL; there are plenty of tutorials around the general setup. In the example below, we’ll extract the text, author information, and time of each comment.

First, make sure that in your app settings within Facebook, Migration->July 2013 Breaking Changes is “Disabled” (thanks for Darius for the tip!).

Then, using the Graph API Explorer, you can perfect the exact query that you need:

Facebook Graph API Explorer

Select your application in the top right, choose to do an FQL query, and then run a query on the “comment” table:

SELECT time, text, fromid FROM comment WHERE xid = 87902

Note that you do not need to use a “WHERE” clause specifying the “app_id” value — if you do, you will not get any results. It is your access token that already puts you in the scope of the correct application.

Basically, you’ll have to generate, from your website, a list of all the xid values (in other words, page IDs that could possibly have comments), and then pass it to Facebook. FQL supports passing multiple xid values with the “IN” syntax, so you can run a query like this:

SELECT xid, time, text, fromid FROM comment WHERE xid IN ( 87900, 87901, 87902, 87903, 87904 )

As shown in the screenshot above, you will get a JSON result with entries for each comment.

The “fromid” value is the Facebook user ID. For each result, you can directly call a Graph API REST URL to get information about the user’s name:

https://graph.facebook.com/[fromid]

This should yield a JSON result similar to this:

{
   "id": "883724954",
   "name": "Joe Smith",
   "first_name": "Joe",
   "last_name": "Smith",
   "link": "https://www.facebook.com/joesmith",
   "username": "joesmith",
   "gender": "male",
   "locale": "en_GB"
}
Arrow

4 Responses to “Exporting Facebook comments from Comments Box using xid and migrated=1”


  1. Darius says:

    I don’t know why but for me this example doesn’t work. I tried:
    SELECT fromid, time, text FROM comment WHERE xid=3707945

    and I’m getting error "Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://developers.facebook.com/docs/reference/fql"

    I also tried "SELECT fromid, time, text FROM comment WHERE id=3707945". But result is the same.

    Reply from Peter: My guesses: you need to select a specific application in the top right dropdown if you’re in the Graph API Explorer; or your comments don’t use the migrated parameter.


  2. Darius says:

    Peter, I’m selected specific application in the top right dropdown. Today I’m getting empty result.
    The URL with xid is http://pigu.lt/foto_gsm_mp3/mobilieji_telefonai/telefonas_samsung_galaxy_note_ii?id=3707945

    Reply from Peter: I don’t know what else the problem could be, unfortunately. If you discover the solution, please post it!


  3. Darius says:

    I found the problem. Problem were in advanced FB apps settings. Migration->July 2013 Breaking Changes must be Disabled. If this setting is Enabled then FQL returns empty array.

    Reply from Peter: Thanks for sharing the solution! I have updated the original post to add this information.


  4. Christian says:

    Hi,

    We facing a similar issue with the Facebook Comment; We currently using the legacy "xid" method to manage comments on our website but we can’t do any reply to comments anymore. We always get an error message like:

    "Oops!, Something went wrong. We’re working on getting it fixed as soon as we can."

    So we try to migrate with the new 2013 API using "href" parameters where the reply is fix but we lost all comments done with the "xid" method, that insane!

    Do you have any idea why is this happening ? What can we do to retrieve old comments from "xid" approach and migrate to "href" approach ?

    Thanks!

    Reply from Peter: The “trick” might no longer be valid after July 2013. Hope you’re able to find a solution!

Speak your mind

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word