- An 'Unofficial' library for the Facebook API in Java -

1. How do I specify API version of Facebook?

You can specify in the configuration.

via facebook4j.properties

Please add the following to the facebook4j.properties of your application.


via ConfigurationBuilder

Please set the API version to ConfigurationBuilder .

ConfigurationBuilder cb = new ConfigurationBuilder();
  .setRestBaseURL("https://graph.facebook.com/v2.0/");  // <- set v2.0
FacebookFactory ff = new FacebookFactory(cb.build());
Facebook facebook = ff.getInstance();

via System Properties

Note that you need “facebook4j.” prefix.

$ java -Dfacebook4j.debug=true

2. How to extend expiration of my access token?

See Facebook’s Documentation: Expiration and Extension of Access Tokens

You can extend expiration of your short-lived access token as below:

AccessToken extendedToken = facebook.extendTokenExpiration(shortLivedToken);

3. How to Re-Authentication my app? {reauthentication}

See Facebook’s Documentation: Re-Authentication

You can build your force Re-Authentication URL as below:

String reAuthUrl = facebook.getOAuthReAuthenticationURL(callbackURL, "random_nonce");

2nd argument is ‘auth_nonce’ parameter that is a completely arbitrary alphanumeric code that your app generates. It can be used to provide replay protection. You should check this nonce hasn’t been used before.

4. How to re-ask for a declined permissions?

See Facebook’s Documentation: Re-asking for Declined Permissions

One of the best practices with Facebook Login is to not request read permissions and publishing permissions at the same time. To support this your app can ask for more permissions later, well after someone has logged in.

AuthOption authOption = new DialogAuthOption().authType(AuthType.REREQUEST);
String url = facebook.getOAuthAuthorizationURL(callbackURL, authOption);