我需要你的帮助。
我正在使用restfb库开发一个java应用程序,我希望在fb上获得所有喜欢我的粉丝页面的facebook用户。我工作了很多天才做到这一点,但我找不到解决方案。
我写了这段代码,但它只返回了likers的数量:
FacebookClient fb= new DefaultFacebookClient("ACCESS_TOKEN");
Page page = fb.fetchObject("PAGE_ID", Page.class);
System.out.println("My pages likes: " + page.getLikes());
请注意,当我登录fb页面时,我从Graph API资源管理器获取ACCESS_TOKEN,因为我没有找到从java代码获取令牌的方法。所以当我退出海时出现这个错误:
Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Error validating access token: The session is invalid because the user logged out.
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:766)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:688)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:630)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:592)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:556)
at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:244)
at testrestfb.testfb.main(testfb.java:95)
请帮我解决这个问题..
提前致谢。
答案 0 :(得分:0)
您应该使用fql查询获取有关此类信息的信息。
请参阅下面的“拨打更复杂的电话”
这里我们让API调用fql.query来执行自定义查询。
// FQL query which asks Facebook for your friends' names,
// profile picture URLs, and network affiliations
String query =
"SELECT name, pic_big, affiliations FROM user " +
"WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=12345)";
// Executes an API call with result mapped to a list of classes we've defined.
// Note that you can pass in an arbitrary number of Parameters - here we
// send along the query as well as the "give me HTTPS URLs" flag
List<User> users =
facebookClient.executeForList("fql.query", sessionKey, User.class,
Parameter.with("query", query), Parameter.with("return_ssl_resources", "true"));
详情为here