Facebook Query Language ( FQL )

Prabu D

1 min read

Recently I worked for a project, which fetches data from Facebook and save data locally, Initially we were using Graph API and later migrated to FQL. I would like to share my knowledge about FQL. FQL is Facebook’s SQL alternative, It allows us to query information from Facebook database.
There are 2 options to retrieve data of Facebook pages
1) Graph API
2) FQL

Why FQL ?

Using Graph API it is not possible to make a bulk fetch, eg : If we need to retrieve all the albums and photos of an album then we need to make multiple calls to achieve this. It will increase response time, which affects the performance of the system.
This is where FQL comes in and resolve this problem , which helps us to make a single call to fetch all the data, In our examples, We can retrieve all the albums and photos of an album in a single call, fetch the data, parse and save it to the DB.

FQL Features

FQL enables SQL-style interface to query the data exposed by the Graph API and It provides advanced features that are not available in the Graph API, which includes batching multiple queries in a single call which improves the application performance a lot.

Refer the documents click here

FQL Tables

      album – An album of photos or videos as represented in FQL.
      event – An FQL table that returns information about an event.
      stream – An FQL table that can be used to return a list of a stream posts.
      video – An FQL table containing information about videos.
      profile_pic – An FQL table that returns profile pictures closest to a requested size.


Give a HTTP GET request to

Where query can be a single FQL query or a JSON-encoded dictionary of queries.
Example : Single FQL query
query = SELECT name FROM user WHERE uid = me()
Example : JSON encoded dictionary of queries
“query1″:”SELECT uid, rsvp_status FROM event_member WHERE eid=12345678”
“query2″:”SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)”
You can fetch data from query1 and use it in another query2 within the same call.

FQL is still available in version 2.0, but will not be available in the next version of the API.

Facebook Explorer

Example ruby code to fetch events details using FQL

class Fql
def fql_update_events()
query = get_fql_events_query()
events_data = RestClient.get(query)
if events_data
events_data = JSON.parse (events_data)
puts “f_events=#{f_events.to_s}”
rescue Exception => ex1
puts ex1.to_s
def get_fql_events_query()
@@app_token = “APPID AND SECRET KEY”
@@page_id = “FACEBOOK PAGE ID”
query1 = “{\”f_events\”:\”select eid, name, description, pic_cover, creator,start_time, end_time, venue, location, pic_big, all_members_count, attending_count, unsure_count from event where creator = #{@@page_id} \”}”
query2 = “https://graph.facebook.com/fql?q=”
query=query2 + escquery + “&access_token=#{@@app_token}”
return query
fql = Fql.new
Hope this will help you to understand FQL and use it in your project.
Happy Coding 🙂

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *