I'm trying to retrieve the number of likes a facebook page has. Here's my code:
FacebookClient fb= new DefaultFacebookClient(tok, appSecret);
Page page = fb.fetchObject("178697151159", Page.class, Parameter.with("likes", "true"));
System.out.println("My pages likes: " + page.getLikes());
but, its giving null as output. I'm new to restFB. So please help me in getting this.
Thank you.
try this:
FacebookClient client = new DefaultFacebookClient(token, Version.VERSION_2_6);
Page page = client.fetchObject("178697151159", Page.class, Parameter.with("fields","fan_count"));
System.out.println("My page likes: " + page.getFanCount());
You have to tell Facebook which fields (fan_count
) you need and you should use the newest API (2.6
).
Then the rest is very easy :)