1

我需要你的帮助。

我正在使用 restfb 库开发一个 java 应用程序,我想在其中获取所有喜欢我在 fb 上的粉丝页面的 facebook 用户。我为此工作了很多天,但我没有找到解决方案。

我写了这段代码,但它只返回喜欢的人数:

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 Explorer 获取 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)

请帮我解决这个问题..

提前致谢。

4

1 回答 1

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"));

详情在这里

于 2013-11-07T12:31:16.353 回答