1

I am using facebook4j-core-2.1.0 and trying to get the page likes. I don't know what I am doing wrong, I am kinda newbie at this.

    public static void main(String[] args) throws FacebookException
    {
        // Generate facebook instance.
        Facebook facebook = new FacebookFactory().getInstance();

        // access token ...

        AccessToken at = new AccessToken(accessTokenString);        

        // Set access token.
        facebook.setOAuthAccessToken(at);

        String facebookUserName = "Google";

        Page pgId = facebook.getPage(facebookUserName);
        Page pgL = facebook.getLikedPage(pgId.getId());
        System.out.println("Page Likes :" + pgL);
    }

http://www.facebook.com/Google shows that it have 18,281,664 likes, but when I ran the above code I got null value.

What am I missing here?

pro_newbie
  • 336
  • 2
  • 6
  • 19

2 Answers2

1

I think you should try something like this:

String userName = "google";     
Page pgId = facebook.getPage(userName);
System.out.println("Page Likes :" + pgId.getLikes());

Hope it helps.

nice guy
  • 151
  • 1
  • 14
-1

The page.getLikes() method return null to me so I opted for this:

RawAPIResponse facebookJson = facebook.callGetAPI("google?fields=engagement");
JSONObject jsonObject = facebookJson.asJSONObject();
String likesCount = ((JSONObject)jsonObject.get("engagement")).getString("count");
System.out.println("likes :" + likesCount);

Using Reading and api v2.6 see how to specify api version here http://facebook4j.org/en/faq.html#apiversion

Reading pageReading = new Reading();
pageReading.fields("name","id","fan_count");
Page page = facebook.getPage("google", pageReading);
System.out.println("likes :" + page.getFanCount());
Albert
  • 1
  • 1