[英]Facebook4j get page likes
I am using facebook4j-core-2.1.0 and trying to get the page likes. 我正在使用facebook4j-core-2.1.0并尝试获得喜欢的页面。 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. http://www.facebook.com/Google显示它有18,281,664个顶 ,但是当我运行以上代码时,我得到了空值。
What am I missing here? 我在这里想念什么?
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. 希望能帮助到你。
The page.getLikes()
method return null
to me so I opted for this: page.getLikes()
方法向我返回null
,所以我选择了这一点:
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
和api v2.6查看如何在此处指定api版本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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.