Since Camel 2.14
Both producer and consumer are supported
The Facebook component provides access to all of the Facebook APIs accessible using Facebook4J. It allows producing messages to retrieve, add, and delete posts, likes, comments, photos, albums, videos, photos, checkins, locations, links, etc. It also supports APIs that allow polling for posts, users, checkins, groups, locations, etc.
Facebook requires the use of OAuth for all client application authentication. In order to use camel-facebook with your account, you’ll need to create a new application within Facebook at https://developers.facebook.com/apps and grant the application access to your account. The Facebook application’s id and secret will allow access to Facebook APIs which do not require a current user. A user access token is required for APIs that require a logged in user. More information on obtaining a user access token can be found at https://developers.facebook.com/docs/facebook-login/access-tokens/.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-facebook</artifactId>
<version>${camel-version}</version>
</dependency>
URI format
facebook://[endpoint]?[options]
The facebook component can be configured with the Facebook account settings below, which are mandatory. The values can be provided to the component using the bean property configuration of type org.apache.camel.component.facebook.config.FacebookConfiguration. The oAuthAccessToken option may be ommited but that will only allow access to application APIs.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
Component Options
The Facebook component supports 31 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Facebook4J API client URL. | String | ||
Facebook4J client API version. | String | ||
Enables deubg output. Effective only with the embedded logger. | false | Boolean | |
Use Facebook GZIP encoding. | true | Boolean | |
Http connection timeout in milliseconds. | 20000 | Integer | |
HTTP maximum connections per route. | 2 | Integer | |
HTTP maximum total connections. | 20 | Integer | |
Http read timeout in milliseconds. | 120000 | Integer | |
Number of HTTP retries. | 0 | Integer | |
HTTP retry interval in seconds. | 5 | Integer | |
HTTP streaming read timeout in milliseconds. | 40000 | Integer | |
If set to true, raw JSON forms will be stored in DataObjectFactory. | false | Boolean | |
If set to true, Facebook4J mbean will be registerd. | false | Boolean | |
Prettify JSON debug output if set to true. | false | Boolean | |
API base URL. | String | ||
Use SSL. | true | Boolean | |
Video API base URL. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
To use the shared configuration. | FacebookConfiguration | ||
HTTP proxy server host name. | String | ||
HTTP proxy server password. | String | ||
HTTP proxy server port. | Integer | ||
HTTP proxy server user name. | String | ||
The user access token. | String | ||
OAuth access token URL. | String | ||
The application Id. | String | ||
The application Secret. | String | ||
OAuth authorization URL. | String | ||
Default OAuth permissions. Comma separated permission names. See https://developers.facebook.com/docs/reference/login/#permissions for the detail. | String |
Endpoint Options
The Facebook endpoint is configured using URI syntax:
facebook:methodName
with the following path and query parameters:
Query Parameters (102 parameters)
Name | Description | Default | Type |
---|---|---|---|
The unique URL of the achievement. | URL | ||
The album ID. | String | ||
The facebook Album to be created or updated. | AlbumUpdate | ||
The ID of the Facebook Application. | String | ||
Location latitude and longitude. | GeoLocation | ||
The checkin ID. | String | ||
Deprecated The checkin to be created. Deprecated, instead create a Post with an attached location. | CheckinUpdate | ||
Facebook4J API client URL. | String | ||
Facebook4J client API version. | String | ||
The comment ID. | String | ||
The facebook Comment to be created or updated. | CommentUpdate | ||
Enables deubg output. Effective only with the embedded logger. | false | Boolean | |
The description text. | String | ||
Distance in meters. | Integer | ||
The domain ID. | String | ||
The domain name. | String | ||
The domain names. | List | ||
The event ID. | String | ||
The event to be created or updated. | EventUpdate | ||
The friend ID. | String | ||
The friend list ID. | String | ||
The friend list Name. | String | ||
The friend user ID. | String | ||
The group ID. | String | ||
Use Facebook GZIP encoding. | true | Boolean | |
Http connection timeout in milliseconds. | 20000 | Integer | |
HTTP maximum connections per route. | 2 | Integer | |
HTTP maximum total connections. | 20 | Integer | |
Http read timeout in milliseconds. | 120000 | Integer | |
Number of HTTP retries. | 0 | Integer | |
HTTP retry interval in seconds. | 5 | Integer | |
HTTP streaming read timeout in milliseconds. | 40000 | Integer | |
The ids of users. | List | ||
Sets the name of a parameter to be passed in the exchange In Body. | String | ||
Enables notifications that the user has already read in addition to unread ones. | Boolean | ||
Whether hidden. | Boolean | ||
If set to true, raw JSON forms will be stored in DataObjectFactory. | false | Boolean | |
Link URL. | URL | ||
Link ID. | String | ||
Desired FQL locale. | Locale | ||
If set to true, Facebook4J mbean will be registerd. | false | Boolean | |
The message text. | String | ||
The message ID. | String | ||
The metric name. | String | ||
The milestone id. | String | ||
Test user name, must be of the form 'first last'. | String | ||
The note ID. | String | ||
The notification ID. | String | ||
The insight object ID. | String | ||
The offer id. | String | ||
The question’s answer option description. | String | ||
The page id. | String | ||
The permission name. | String | ||
Test user permissions in the format perm1,perm2,… | String | ||
The photo ID. | String | ||
The picture id. | Integer | ||
The picture2 id. | Integer | ||
The picture size. Enum values:
| PictureSize | ||
The place ID. | String | ||
The post ID. | String | ||
The post to create or update. | PostUpdate | ||
Prettify JSON debug output if set to true. | false | Boolean | |
FQL queries. | Map | ||
FQL query or search terms for search endpoints. | String | ||
The question id. | String | ||
Optional reading parameters. See Reading Options(#reading). | Reading | ||
To configure Reading using key/value pairs from the Map. | Map | ||
API base URL. | String | ||
The numeric score with value. | Integer | ||
The picture size, one of large, normal, small or square. Enum values:
| PictureSize | ||
The media content from either a java.io.File or java.io.Inputstream. | Media | ||
The note of the subject. | String | ||
The tab id. | String | ||
Photo tag information. | TagUpdate | ||
Test user 1. | TestUser | ||
Test user 2. | TestUser | ||
The ID of the test user. | String | ||
The title text. | String | ||
The ID of the user to tag. | String | ||
The IDs of the users to tag. | List | ||
The Facebook user ID. | String | ||
The ID of a user 1. | String | ||
The ID of a user 2. | String | ||
The IDs of users to invite to event. | List | ||
The test user locale. | String | ||
Use SSL. | true | Boolean | |
Video API base URL. | String | ||
The video ID. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
HTTP proxy server host name. | String | ||
HTTP proxy server password. | String | ||
HTTP proxy server port. | Integer | ||
HTTP proxy server user name. | String | ||
The user access token. | String | ||
OAuth access token URL. | String | ||
The application Id. | String | ||
The application Secret. | String | ||
OAuth authorization URL. | String | ||
Default OAuth permissions. Comma separated permission names. See https://developers.facebook.com/docs/reference/login/#permissions for the detail. | String |
Message Headers
The Facebook component supports 1 message header(s), which is/are listed below:
Name | Description | Default | Type |
---|---|---|---|
CamelFacebook.rawJSON (common) Constant: | The raw json. | String |
Producer Endpoints:
Producer endpoints can use endpoint names and options from the table below. Endpoints can also use the short name without the get or search prefix, except checkin due to ambiguity between getCheckin and searchCheckin. Endpoint options that are not mandatory are denoted by [].
Producer endpoints can also use a special option inBody that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message. For example, the facebook endpoint in the following route retrieves activities for the user id value in the incoming message body.
from("direct:test").to("facebook://activities?inBody=userId")...
Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFacebook.option
. For example, the userId option value in the previous route could alternately be provided in the message header CamelFacebook.userId. Note that the inBody option overrides message header, e.g. the endpoint option inBody=user would override a CamelFacebook.userId header.
Endpoints that return a String return an Id for the created or modified entity, e.g. addAlbumPhoto returns the new album Id. Endpoints that return a boolean, return true for success and false otherwise. In case of Facebook API errors the endpoint will throw a RuntimeCamelException with a facebook4j.FacebookException cause.
Consumer Endpoints:
Any of the producer endpoints that take a reading parameter can be used as a consumer endpoint. The polling consumer uses the since and until fields to get responses within the polling interval. In addition to other reading fields, an initial since value can be provided in the endpoint for the first poll.
Rather than the endpoints returning a List (or facebook4j.ResponseList) through a single route exchange, camel-facebook creates one route exchange per returned object. As an example, if "facebook://home" results in five posts, the route will be executed five times (once for each Post).
Reading Options
The reading option of type facebook4j.Reading adds support for reading parameters, which allow selecting specific fields, limits the number of results, etc. For more information see Graph API documentation.
It is also used by consumer endpoints to poll Facebook data to avoid sending duplicate messages across polls.
The reading option can be a reference or value of type facebook4j.Reading, or can be specified using the following reading options in either the endpoint URI or exchange header with CamelFacebook. prefix.
Message header
Any of the URI options can be provided in a message header for producer endpoints with CamelFacebook.
prefix.
Message body
All result message bodies utilize objects provided by the Facebook4J API. Producer endpoints can specify the option name for incoming message body in the inBody endpoint parameter.
For endpoints that return an array, or facebook4j.ResponseList, or java.util.List, a consumer endpoint will map every elements in the list to distinct messages.
Use cases
To create a post within your Facebook profile, send this producer a facebook4j.PostUpdate body.
from("direct:foo")
.to("facebook://postFeed/inBody=postUpdate);
To poll, every 5 sec (You can set the polling consumer options by adding a prefix of "consumer"), all statuses on your home feed:
from("facebook://home?delay=5000")
.to("bean:blah");
Searching using a producer with dynamic options from header.
In the bar header we have the Facebook search string we want to execute in public posts, so we need to assign this value to the CamelFacebook.query header.
from("direct:foo")
.setHeader("CamelFacebook.query", header("bar"))
.to("facebook://posts");
Spring Boot Auto-Configuration
When using facebook with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-facebook-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 32 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean | |
Facebook4J API client URL. | String | ||
Facebook4J client API version. | String | ||
To use the shared configuration. The option is a org.apache.camel.component.facebook.config.FacebookConfiguration type. | FacebookConfiguration | ||
Enables deubg output. Effective only with the embedded logger. | false | Boolean | |
Whether to enable auto configuration of the facebook component. This is enabled by default. | Boolean | ||
Use Facebook GZIP encoding. | true | Boolean | |
Http connection timeout in milliseconds. | 20000 | Integer | |
HTTP maximum connections per route. | 2 | Integer | |
HTTP maximum total connections. | 20 | Integer | |
HTTP proxy server host name. | String | ||
HTTP proxy server password. | String | ||
HTTP proxy server port. | Integer | ||
HTTP proxy server user name. | String | ||
Http read timeout in milliseconds. | 120000 | Integer | |
Number of HTTP retries. | 0 | Integer | |
HTTP retry interval in seconds. | 5 | Integer | |
HTTP streaming read timeout in milliseconds. | 40000 | Integer | |
If set to true, raw JSON forms will be stored in DataObjectFactory. | false | Boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean | |
If set to true, Facebook4J mbean will be registerd. | false | Boolean | |
The user access token. | String | ||
OAuth access token URL. | String | ||
The application Id. | String | ||
The application Secret. | String | ||
OAuth authorization URL. | String | ||
Default OAuth permissions. Comma separated permission names. See https://developers.facebook.com/docs/reference/login/#permissions for the detail. | String | ||
Prettify JSON debug output if set to true. | false | Boolean | |
API base URL. | String | ||
Use SSL. | true | Boolean | |
Video API base URL. | String |