0

I am trying to retrieve the total number of likes for a facebook page using facebook4j.

Here is my code snippet:

    final Reading reading = new Reading().fields("id","about","name","likes");
    Page p = facebook.getPage("green", reading); 

    System.out.println("page name: "+p.getName());
    System.out.println("page id: "+p.getId());
    System.out.println("About the page: "+p.getAbout());
    System.out.println("likes: "+p.getLikes());

I'm getting all property values except likes (showing null). Any help on this could be greatly appreciated.

Arjun A J
  • 396
  • 1
  • 9
  • 34

1 Answers1

0

https://developers.facebook.com/docs/graph-api/reference/page/:

likes: The Pages that this Page Likes.

You are requesting the wrong field. What you want, is

fan_count: The number of users who like the Page. For Global Pages this is the count for all Pages across the brand.

CBroe
  • 91,630
  • 14
  • 92
  • 150
  • 1
    I got your point. I searched through the page related methods in facebook4j, but i didn't found one to get the fan_count value. Moreover, there is no field in the JSON array produced for a specific **Page** object. Can you please tell me how to get this value in my program? – Arjun A J Jun 14 '16 at 02:58
  • First of all, I need to set `.setRestBaseURL("https://graph.facebook.com/v2.6/") // we need fan_count` during FacebookFactory configuration. Now, actually getting the `fan_count`.. As you mentioned, it's not even in the `facebook4j.Page` interface yet – Hendy Irawan Jun 27 '16 at 16:28
  • I have set the base url as you said. I have also mentioned fan_count field in the list of fields that i want to access. But I'm not getting the fan_count field in the response json array. Can you please tell me where I can get that field's value? – Arjun A J Jun 29 '16 at 08:27
  • Try and make that same request (using your app and same access token) in Graph API Explorer, to check it works - https://developers.facebook.com/tools/explorer If it does, then it might rather be a problem of the framework/SDK. – CBroe Jun 29 '16 at 09:18
  • Since i'm using API's from facebook4j to get data, i'm not used to it. Can you please post the query to be made in Graph API Explorer? – Arjun A J Jul 01 '16 at 05:52