Take the 2-minute tour ×

I'm currently trying to get the total number of "likes" from a post. If I query the post via the Graph API Exporer, the data is there under likes.data.count. From my javascript application, the returned object only contains "id" and "created_time".

I have checked using the access token debugger and I have permissions to access user_likes and friends_likes so I am really at a loss to what's missing. However, I do suspect that this is a permissions issue. Does anyone know why I can't get the likes count on a post?

My query looks like this:

                    FB.api(postid + "?fields=likes",  
                      function(response) {

                      if (!response || response.error) {
                        alert('Error occured' + response.error);
                      } else {
                        alert("got response: " + JSON.stringify(response));                          
                        likecount = response.likes.data.count;
                        alert('likecount: ' + likecount);

And my initialization code looks like this:

                    FB.init({ appId: '373915339387251', 
                              status: true, 
                              cookie: true,
                              xfbml: true,
                              oauth: true});

                    button.onclick = function() {
                        FB.login(function(response) {
                            if (response.authResponse) {
                                FB.api('/me', function(info) {
                                    login(response, info);
                            } else {
                                //user cancelled login or did not grant authorization
                        }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me,user_likes,friends_likes'});      
share|improve this question
Hi? Are you there? I think I found an answer. –  Jorge Fuentes González Jun 5 '13 at 18:50
Thanx for accepting :) –  Jorge Fuentes González Jun 8 '13 at 14:52
add comment

1 Answer

up vote 0 down vote accepted

An example of response data received is this (Extracted from here):

"likes": {
    "data": [
        "name": "Mia Lusiana", 
        "id": "100003399221230"
        "name": "Habeeb Quazi", 
        "id": "525927716"
        "name": "Mert Vrss", 
        "id": "100002500864051"
        "name": "Nav", 
        "id": "100000757486687"
    "count": 8145

as you can see, count is inside likes, not inside data, so it must be this way:

likecount = response.likes.count;

data contains people that liked the post.

share|improve this answer
Hi Jorge, I have updated the question with my initialization code. –  Brendan Howell Jun 5 '13 at 16:17
You have scope instead of perms. I don't know how FB works right now, so many time without coding FB apps but maybe the problem is there. –  Jorge Fuentes González Jun 5 '13 at 16:21
Ok, I've just read in FB docs that is scope. I don't know where is the problem then :-/ Sorry... –  Jorge Fuentes González Jun 5 '13 at 16:22
Ok, just checked a graph api response and I think I got it. I've edited my answer. –  Jorge Fuentes González Jun 5 '13 at 16:28
add comment

Your Answer


