Facebook4J

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

How to specify the API version of Facebook, please see here.

Generic properties

There are a number of properties available for configuring Facebook4J. You can specify properties via facebook4j.properties file, ConfigurationBuilder class or System Property as follows :

via facebook4j.properties

Save a standard properties file named “facebook4j.properties”. Place it to either the current directory, root of the classpath directory.

debug=true
oauth.appId=****************
oauth.appSecret=********************************
oauth.accessToken=********************************
oauth.permissions=email,publish_stream,...

via ConfigurationBuilder

You can use ConfigurationBuilder class to configure Facebook4J programatically as follows:

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
  .setOAuthAppId("*********************")
  .setOAuthAppSecret("******************************************")
  .setOAuthAccessToken("**************************************************")
  .setOAuthPermissions("email,publish_stream,...");
FacebookFactory ff = new FacebookFactory(cb.build());
Facebook facebook = ff.getInstance();

via System Properties

You can configure Facebook4J via System properties as well. Note that you need “facebook4j.” prefix.

$ java -Dfacebook4j.debug=true
    -Dfacebook4j.oauth.appId=*********************
    -Dfacebook4j.oauth.appSecret=******************************************
    -Dfacebook4j.oauth.accessToken=**************************************************
    -Dfacebook4j.oauth.permissions=email,publish_stream,...
    -cp facebook4j-core-2.4.13.jar:yourApp.jar yourpackage.Main

via environment variables

You can configure Facebook4J via environment variables as well. Note that you need “facebook4j.” prefix. This makes it easier to test, stage and deploy apps running on Heroku.

$ export facebook4j.debug=true
$ export facebook4j.oauth.appId=*********************
$ export facebook4j.oauth.appSecret=******************************************
$ export facebook4j.oauth.accessToken=**************************************************
$ export facebook4j.oauth.permissions=email,publish_stream,...
$ java -cp facebook4j-core-2.4.13.jar:yourApp.jar yourpackage.Main

On Heroku:

$ heroku config:add facebook4j.oauth.appId=*********************
$ heroku config:add facebook4j.oauth.appSecret=******************************************
$ heroku config:add facebook4j.oauth.accessToken=**************************************************
$ heroku config:add facebook4j.oauth.permissions=email,publish_stream,...
$ git push heroku master

Available Configuration Properties

Misc.

Property nameDescriptionDefault
value
debugEnables deubg output. Effective only with the embedded logger.false
jsonStoreEnabledIf set to true, raw JSON forms will be stored in DataObjectFactory.false
mbeanEnabledIf set to true, mbean will be registerd.false
loggerFactoryLogger implimentation
Supported implimentations:
 facebook4j.internal.logging.SLF4JLoggerFactory
 facebook4j.internal.logging.CommonsLoggingLoggerFactory
 facebook4j.internal.logging.Log4JLoggerFactory
 facebook4j.internal.logging.JULLoggerFactory
 facebook4j.internal.logging.NullLoggerFactory
 facebook4j.internal.logging.StdNullLoggerFactory
null

OAuth

Property nameDescriptionDefault
value
oauth.appIdDefault OAuth App IDnull
oauth.appSecretDefault OAuth App Secretnull
oauth.accessTokenDefault OAuth access tokennull
oauth.permissionsDefault OAuth permissions
Comma separeted permission names
See https://developers.facebook.com/docs/reference/login/#permissions for the detail.
null
oauth.callbackURLDefault OAuth callback URLnull

Security

Property nameDescriptionDefault
value
security.appSecretProofEnabledIf set to true, 'appsecret_proof' parameter will be added to every API call automatically.false
security.appSecretProofCacheSizeCache size for computed appsecret_proof.10

HTTP connection

Property nameDescriptionDefault
value
http.connectionTimeoutHttp connection timeout in milliseconds20000
http.readTimeoutHttp read timeout in milliseconds120000
http.retryCountNumber of HTTP retries0
http.retryIntervalSecsHTTP retry interval in seconds5
http.prettyDebugprettify JSON debug output if set to true.false

HTTP proxy server

Property nameDescriptionDefault
value
http.proxyHostHTTP proxy server host namenull
http.proxyPortHTTP proxy server portnull
http.proxyUserHTTP proxy server user namenull
http.proxyPasswordHTTP proxy server passwordnull

Base URLs

Property nameDescriptionDefault
value
restBaseURLAPI base URLhttps://graph.facebook.com/
videoBaseURLVideo API base URLhttps://graph-video.facebook.com/
oauth.authorizationURLOAuth authorization URLhttps://www.facebook.com/dialog/oauth
oauth.accessTokenURLOAuth access token URLhttps://graph.facebook.com/oauth/access_token
oauth.accessTokenInfoURLOAuth access token information URLhttps://graph.facebook.com/oauth/access_token_info
oauth.deviceTokenURLOAuth device access token URLhttp://graph.facebook.com/oauth/device

Logger Configuration

By default, Facebook4J prints log messages to standard output. If any of SLF4J, Commons-Logging, Log4J is in the classpath, log messages will be printed via the available logging library. You can disable logging by specifying -Dfacebook4j.loggerFactory=facebook4j.internal.logging.NullLoggerFactory to the system properties.