Question: I am building a rails app where there is an image gallery and users will be able to hit the facebook like button for each image they open. Each image can have its seperate page URL. I plan to use the facebook like plugin so that users can like the photos as web-pages. So far I was able to find that if I do `https://graph.facebook.com/?id=http://www.mysite.com/ImagePage` i get:

```
{
   "id": "http://www.mysite.com/ImagePage",
   "shares": 30
}

```

This leaves me with 2 problems.

1. The `shares` property is not exactly the total count of likes, it is only the count of times the link made it to the user's facebook wall. How do I get the number of likes?
2. Is there an eventHandler or something I can use to know when a user clicks Like? so that I can store that information? I want to store the likes count at my end so that I can show the gallery in the order of descending number of total likes in each day.

I have come across the rails Koala gem but I am not sure if I need to use that for my application yet, as I do not have the need to log in users using facebook login/connect. Please advise if you think I need to do so to do what I mentioned above.

Answer: 
you have to use FQL. 

see this example in php, im sure you know how to handle it in ruby:

```
$fql = 'SELECT url, share_count, like_count, comment_count, total_count
        FROM link_stat WHERE url="http://stackoverflow.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));

```

result looks like:

```
[
    {
        "url"           : "http://stackoverflow.com",
        "share_count"   : 1353,
        "like_count"    : 332,
        "comment_count" : 538,
        "total_count"   : 2223
    }
]

```
For those who don't know how to modify the code seen in the previous answer by yourself, you mostly have two choices:

* Use facebook gems available that support running FQL queries (for example: [fb\_graph](https://github.com/nov/fb_graph))

*Sample code:*

```
require 'fb_graph'

array = FbGraph::Query.new(
  'SELECT name FROM user WHERE uid = me()'
).fetch(ACCESS_TOKEN)

p array

```

* Use a simple Ruby code that basically just does FQL queries, as seen on this accepted answer ([Facebook FQL Query with Ruby](https://stackoverflow.com/questions/7178590/facebook-fql-query-with-ruby))