Facebook4J OAuth失败了

时间:2016-05-02 15:03:59

标签: java facebook facebook-graph-api facebook4j

我正在尝试使用Facebook4J搜索公共项目,我知道我需要一个appId和appSecret我有,app标记是这两个在它们之间有管道符号(据我所知)。我无法理解为什么我会遇到OAuthError,请参阅下面的代码和精确的错误代码。

    facebook4j.conf.ConfigurationBuilder fac = new facebook4j.conf.ConfigurationBuilder();

    fac.setDebugEnabled(true)
      .setOAuthAppId("appId")
      .setOAuthAppSecret("appSecret")
      .setOAuthPermissions("email,publish_stream");
    fac.setOAuthAccessToken(accessToken);
    FacebookFactory ff = new FacebookFactory(fac.build());
   Facebook facebook = ff.getInstance();

   ResponseList<JSONObject> results = facebook.search("%whatever");

这是我得到的以下错误代码。错误代码一似乎是未知的API ???

线程“主”消息中的异常 - 发生了未知错误。 代码 - 1 可以在Facebook Developers Document上找到有关错误恢复的相关信息:     https://developers.facebook.com/docs/graph-api/using-graph-api/#errors

FacebookException{statusCode=500, errorType='OAuthException', errorMessage='An unknown error has occurred.', errorCode=1, errorSubcode=-1, version=2.4.2}
    at facebook4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:179)
    at facebook4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
    at facebook4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:89)
    at facebook4j.FacebookImpl.get(FacebookImpl.java:2742)
    at facebook4j.FacebookImpl.search(FacebookImpl.java:2337)
    at facebook4j.FacebookImpl.search(FacebookImpl.java:2332)
    at Main.facebook4JRequest(Main.java:37)
    at Main.main(Main.java:15)

1 个答案:

答案 0 :(得分:1)

尝试使用以下适用于我的代码。

Facebook facebook = new FacebookFactory().getInstance();  
facebook.setOAuthAppId("XXXXXX", "XXXXXXXXXXXX");
String accessTokenString = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
AccessToken at = new AccessToken(accessTokenString);
facebook.setOAuthAccessToken(at);

ResponseList<Post> feeds = facebook.getPosts("%whatever", new Reading().limit(80));