Facebook Component

Table of Contents

URI format
FacebookComponent
Producer Endpoints:
Consumer Endpoints:
Reading Options
Message header
Message body
Use cases

Available as of Camel 2.12

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]

FacebookComponent

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.

The Facebook component supports 1 options which are listed below.

{% raw %}

NameJava TypeDescription

configuration

FacebookConfiguration

To use the shared configuration

{% endraw %}

The Facebook component supports 103 endpoint options which are listed below:

{% raw %}

NameGroupDefaultJava TypeDescription

methodName

common

 

String

Required What operation to perform

achievementURL

common

 

URL

The unique URL of the achievement

albumId

common

 

String

The album ID

albumUpdate

common

 

AlbumUpdate

The facebook Album to be created or updated

appId

common

 

String

The ID of the Facebook Application

center

common

 

GeoLocation

Location latitude and longitude

checkinId

common

 

String

The checkin ID

checkinUpdate

common

 

CheckinUpdate

The checkin to be created. Deprecated instead create a Post with an attached location

clientURL

common

 

String

Facebook4J API client URL

clientVersion

common

 

String

Facebook4J client API version

commentId

common

 

String

The comment ID

commentUpdate

common

 

CommentUpdate

The facebook Comment to be created or updated

debugEnabled

common

false

Boolean

Enables deubg output. Effective only with the embedded logger

description

common

 

String

The description text

distance

common

 

Integer

Distance in meters

domainId

common

 

String

The domain ID

domainName

common

 

String

The domain name

domainNames

common

 

List

The domain names

eventId

common

 

String

The event ID

eventUpdate

common

 

EventUpdate

The event to be created or updated

friendId

common

 

String

The friend ID

friendlistId

common

 

String

The friend list ID

friendlistName

common

 

String

The friend list Name

friendUserId

common

 

String

The friend user ID

groupId

common

 

String

The group ID

gzipEnabled

common

true

Boolean

Use Facebook GZIP encoding

httpConnectionTimeout

common

20000

Integer

Http connection timeout in milliseconds

httpDefaultMaxPerRoute

common

2

Integer

HTTP maximum connections per route

httpMaxTotalConnections

common

20

Integer

HTTP maximum total connections

httpReadTimeout

common

120000

Integer

Http read timeout in milliseconds

httpRetryCount

common

0

Integer

Number of HTTP retries

httpRetryIntervalSeconds

common

5

Integer

HTTP retry interval in seconds

httpStreamingReadTimeout

common

40000

Integer

HTTP streaming read timeout in milliseconds

ids

common

 

List

The ids of users

inBody

common

 

String

Sets the name of a parameter to be passed in the exchange In Body

includeRead

common

 

Boolean

Enables notifications that the user has already read in addition to unread ones

isHidden

common

 

Boolean

Whether hidden

jsonStoreEnabled

common

false

Boolean

If set to true raw JSON forms will be stored in DataObjectFactory

link

common

 

URL

Link URL

linkId

common

 

String

Link ID

locale

common

 

Locale

Desired FQL locale

mbeanEnabled

common

false

Boolean

If set to true Facebook4J mbean will be registerd

message

common

 

String

The message text

messageId

common

 

String

The message ID

metric

common

 

String

The metric name

milestoneId

common

 

String

The milestone id

name

common

 

String

Test user name must be of the form 'first last'

noteId

common

 

String

The note ID

notificationId

common

 

String

The notification ID

objectId

common

 

String

The insight object ID

offerId

common

 

String

The offer id

optionDescription

common

 

String

The question’s answer option description

pageId

common

 

String

The page id

permissionName

common

 

String

The permission name

permissions

common

 

String

Test user permissions in the format perm1perm2…​

photoId

common

 

String

The photo ID

pictureId

common

 

Integer

The picture id

pictureId2

common

 

Integer

The picture2 id

pictureSize

common

 

PictureSize

The picture size

placeId

common

 

String

The place ID

postId

common

 

String

The post ID

postUpdate

common

 

PostUpdate

The post to create or update

prettyDebugEnabled

common

false

Boolean

Prettify JSON debug output if set to true

queries

common

 

Map

FQL queries

query

common

 

String

FQL query or search terms for search endpoints

questionId

common

 

String

The question id

reading

common

 

Reading

Optional reading parameters. See Reading Options(reading)

readingOptions

common

 

Map

To configure Reading using key/value pairs from the Map.

restBaseURL

common

https://graph.facebook.com/

String

API base URL

scoreValue

common

 

Integer

The numeric score with value

size

common

 

PictureSize

The picture size one of large normal small or square

source

common

 

Media

The media content from either a java.io.File or java.io.Inputstream

subject

common

 

String

The note of the subject

tabId

common

 

String

The tab id

tagUpdate

common

 

TagUpdate

Photo tag information

testUser1

common

 

TestUser

Test user 1

testUser2

common

 

TestUser

Test user 2

testUserId

common

 

String

The ID of the test user

title

common

 

String

The title text

toUserId

common

 

String

The ID of the user to tag

toUserIds

common

 

List

The IDs of the users to tag

userId

common

 

String

The Facebook user ID

userId1

common

 

String

The ID of a user 1

userId2

common

 

String

The ID of a user 2

userIds

common

 

List

The IDs of users to invite to event

userLocale

common

 

String

The test user locale

useSSL

common

true

Boolean

Use SSL

videoBaseURL

common

https://graph-video.facebook.com/

String

Video API base URL

videoId

common

 

String

The video ID

bridgeErrorHandler

consumer

false

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/ERROR level and ignored.

exceptionHandler

consumer (advanced)

 

ExceptionHandler

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.

exchangePattern

consumer (advanced)

 

ExchangePattern

Sets the exchange pattern when the consumer creates an exchange.

synchronous

advanced

false

boolean

Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).

httpProxyHost

proxy

 

String

HTTP proxy server host name

httpProxyPassword

proxy

 

String

HTTP proxy server password

httpProxyPort

proxy

 

Integer

HTTP proxy server port

httpProxyUser

proxy

 

String

HTTP proxy server user name

oAuthAccessToken

security

 

String

The user access token

oAuthAccessTokenURL

security

https://graph.facebook.com/oauth/access_token

String

OAuth access token URL

oAuthAppId

security

 

String

The application Id

oAuthAppSecret

security

 

String

The application Secret

oAuthAuthorizationURL

security

https://www.facebook.com/dialog/oauth

String

OAuth authorization URL

oAuthPermissions

security

 

String

Default OAuth permissions. Comma separated permission names. See https://developers.facebook.com/docs/reference/login/permissions for the detail

{% endraw %}

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.https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=CAMEL&title=option&linkCreation=true&fromPageId=34020899[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#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#reading - Facebook Developers.

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#urioptions 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?consumer.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");