Mar 02 2011

How To Retrieve Facebook Comments Using Ruby and Koala

Facebook Ruby | comments

I have used fb_graph gem but found it insufficient. There are several Ruby gems for facebook by the way. I suggest using koala. Koala supports OAuth, REST API and the recommended Graph API.

Add the gem on your Gemfile if you are using Rails 3 or Sinatra with bundler.

              gem 'koala'
              

To retrieve Facebook comments for a site, it is quite simple. Just query or get all xid's on comments_info table and when you get all xid's, you can select the comments. The query looks like SQL. FQL is actually less than SQL (LIKE is not supported).

              @rest = Koala::Facebook::RestAPI.new(token)
              @all_comments = @rest.fql_query("SELECT id, fromid, xid, text, time from comment WHERE xid IN (#{@comments_ids.join(",")})")