简体   繁体   中英

Facebook4J OAuth failing

I am trying to search for public items using Facebook4J, I understad I need an appId AND appSecret which I have, the app token is the these two with a pipe symbol between them (as I understand). I can not understand why I am gett an OAuthError , Please see my code below and precise error code.

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

This is the following error code I get. Error code one seems to be unknown API???

Exception in thread "main" message - An unknown error has occurred. code - 1 Relevant information for error recovery can be found on the 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)

Try using the below code it worked for me.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM