Available as of Camel
...
2.10
...
The
...
...
component
...
enables
...
the
...
most
...
useful
...
features
...
of
...
the
...
...
API
...
by
...
encapsulating
...
...
.
...
It
...
allows
...
direct,
...
polling,
...
or
...
event-driven
...
consumption
...
of
...
timelines,
...
users,
...
trends,
...
and
...
direct
...
messages.
...
Also,
...
it
...
supports
...
producing
...
messages
...
as
...
status
...
updates
...
or
...
direct
...
messages.
...
...
now
...
requires
...
the
...
use
...
of
...
OAuth
...
for
...
all
...
client
...
application
...
authentication.
...
In
...
order
...
to
...
use
...
camel-twitter
...
with
...
your
...
account,
...
you'll
...
need
...
to
...
create
...
a
...
new
...
application
...
within
...
...
at
...
https://dev.twitter.com/apps/new
...
and
...
grant
...
the
...
application
...
access
...
to
...
your
...
account.
...
Finally,
...
generate
...
your
...
access
...
token
...
and secret.
Maven users will need to add the following dependency to their pom.xml for this component:
Code Block | ||||
---|---|---|---|---|
| ||||
secret. Since all message bodies rely on Twitter4J objects, the additional Twitter4J dependencies will be necessary within your project. Maven users will need to add the following dependency to their {{pom.xml}} for this component: {code:xml} <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-twitter</artifactId> <version>${camel-version}</version> </dependency> <dependency> <groupId>org.twitter4j</groupId> <artifactId>twitter4j-core</artifactId> <version>${twitter4j-version}</version> </dependency> <dependency> <groupId>org.twitter4j</groupId> <artifactId>twitter4j-stream</artifactId> <version>${twitter4j-version}</version> </dependency> {code} h3. URI format {code} twitter://[endpoint]?[options] {code} h3. URI Options || Name || Default Value || Description || | type | direct | direct, event, or polling | | delay | 60 | in seconds | | *consumerKey | {{null}} | Consumer Key | | *consumerSecret | {{null}} | Consumer Secret | | *accessToken | {{null}} | Access Token | | *accessTokenSecret | {{null}} | Access Token Secret | | user | {{null}} | Username, used for user timeline consumption, direct message production, etc. | | keywords| {{null}} | |
URI format
Code Block | ||
---|---|---|
| ||
twitter://endpoint[?options]
|
TwitterComponent:
The twitter component can be configured with the Twitter account settings which is mandatory to configure before using.
You can also configure these options directly in the endpoint.
Option | Description |
---|---|
consumerKey | The consumer key |
consumerSecret | The consumer secret |
accessToken | The access token |
accessTokenSecret | The access token secret |
Consumer Endpoints:
Rather than the endpoints returning a List through one single route exchange, camel-twitter creates one route exchange per returned object. As an example, if "timeline/home" results in five statuses, the route will be executed five times (one for each Status).
Endpoint | Context | Body Type | Notice |
---|---|---|---|
directmessage | direct, polling | twitter4j.DirectMessage |
|
search | direct, polling | twitter4j.Status |
|
streaming/filter | event, polling | twitter4j.Status |
|
streaming/sample | event, polling | twitter4j.Status |
|
streaming/user | event, polling | twitter4j.Status twitter4j.DirectMessage twitter4j.UserList | Camel 2.16: To receive tweets from protected users and accounts. Camel 2.17: DirectMessages, Favorites, Lists, Following events are now supported |
timeline/home | direct, polling | twitter4j.Status |
|
timeline/mentions | direct, polling | twitter4j.Status |
|
|
|
|
|
timeline/retweetsofme | direct, polling | twitter4j.Status |
|
timeline/user | direct, polling | twitter4j.Status |
|
|
|
|
|
|
|
|
|
Producer Endpoints:
Endpoint | Body Type |
---|---|
directmessage | String |
search | List<twitter4j.Status> |
timeline/user | String |
URI Options
Name | Default Value | Description |
---|---|---|
type |
| direct, event, or polling |
delay |
| Delay between polls. The value is 60 seconds by default. The value is in seconds for Camel 2.16 or older. And in millis seconds from Camel 2.17 onwards. |
consumerKey |
| Consumer Key. Can also be configured on the |
consumerSecret |
| Consumer Secret. Can also be configured on the |
accessToken |
| Access Token. Can also be configured on the |
accessTokenSecret |
| Access Token Secret. Can also be configured on the |
user |
| Username, used for user timeline consumption, direct message production, etc. |
locations |
| 'lat,lon;lat,lon;...' Bounding boxes, created by pairs of lat/lons. Can be used for streaming/filter |
keywords |
| 'foo1,foo2,foo3...' |
...
Can |
...
be |
...
used |
...
for |
...
search and streaming/filter |
...
. See Advanced search for keywords syntax for searching with for example OR. | ||
userIds |
| 'username,username...' |
...
Can |
...
be |
...
used |
...
for streaming/filter | ||
filterOld |
| Filter out old tweets, that has previously been polled. This state is stored in memory only, and based on last tweet id. Since Camel 2.11.0 The search producer supports this option |
sinceId |
| Camel 2.11.0: The last tweet id which will be used for pulling the tweets. It is useful when the camel route is restarted after a long running. |
lang |
| Camel 2.11.0: The lang string ISO_639-1 which will be used for searching |
count |
| Camel 2.11.0: Limiting number of results per page. |
numberOfPages |
| Camel 2.11.0: The number of pages result which you want camel-twitter to consume. |
httpProxyHost |
| Camel 2.12.3: The http proxy host which can be used for the camel-twitter. |
httpProxyPort |
| Camel 2.12.3: The http proxy port which can be used for the camel-twitter. |
httpProxyUser |
| Camel 2.12.3: The http proxy user which can be used for the camel-twitter. |
httpProxyPassword |
| Camel 2.12.3: The http proxy password which can be used for the camel-twitter. |
latitude | Camel 2.16: Used by the non-stream geography search to search by latitude. You need to configure all the following options: longitude, latitude, radius, and distanceMetric. | |
longitude | Camel 2.16: Used by the non-stream geography search to search by longitude. You need to configure all the following options: longitude, latitude, radius, and distanceMetric. | |
radius | Camel 2.16: Used by the non-stream geography search to search by radius. You need to configure all the following options: longitude, latitude, radius, and distanceMetric. | |
distanceMetric | km | Camel 2.16: Used by the non-stream geography search, to search by radius using the configured metrics. The unit can either be mi for miles, or km for kilometers. You need to configure all the following options: longitude, latitude, radius, and distanceMetric. |
Message header
Name | Description |
---|---|
| This header is used by the search producer to change the search key words dynamically. |
| Camel 2.11.0: This header can override the option of |
| Camel 2.11.0 This header can override the option of |
| Camel 2.11.0 This header can converrid the option of |
CamelTwitterEvent | Camel 2.17.0 The type of event received (see org.apache.camel.component.twitter.consumer.TwitterEventType) |
CamelTwitterUser1..N | Camel 2.17.0 Identify a party |
CamelTwitterUserRole1..N | Camel 2.17.0 Identify a party role |
Message body
All message bodies utilize objects provided by the Twitter4J API.
Use cases
Tip | ||||
---|---|---|---|---|
| ||||
Twitter REST APIs encapsulated by Twitter4J are subjected to API Rate Limiting. You can find the per method limits in the API Rate Limits documentation. Note that endpoints/resources not listed in that page are default to 15 requests per allotted user per window. |
To create a status update within your Twitter profile, send this producer a String body.
Code Block |
---|
from("direct:foo") .to(" streaming/filter | {info:title=Note} Options: (* = required). {info} h3. Message body {code} All message bodies utilize objects provided by the Twitter4J API. {code} h4. Consumer Endpoints: {div:class=confluenceTableSmall} || Endpoint || Context || Body Type || | directmessage | direct, polling | List<twitter4j.DirectMessage> | | search | direct, polling | List<twitter4j.Tweet> | | streaming/filter | event, polling | List<twitter4j.Status> | | streaming/sample | event, polling | event: twitter4j.Status, polling: List<twitter4j.Status> | | timeline/home | direct, polling | List<twitter4j.Status> | | timeline/mentions | direct, polling | List<twitter4j.Status> | | timeline/public | direct, polling | List<twitter4j.Status> | | timeline/retweetsofme | direct, polling | List<twitter4j.Status> | | timeline/user | direct, polling | List<twitter4j.Status> | {div} h4. Producer Endpoints: {div:class=confluenceTableSmall} || Endpoint || Body Type || | directmessage | String | | timeline/user | String | {div} h3. Use cases h4. To create a status update within your Twitter profile, send this producer a String body. {code} twitter://timeline/user?consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s] {code} h4. To ); |
To poll,
...
every
...
60 sec.,
...
all
...
statuses
...
on
...
your
...
home
...
timeline:
Code Block |
---|
from(" {code} twitter://timeline/home?type=polling&delay=560&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s] {code} h4. To search for all statuses with the keyword ") .to("bean:blah"); |
To search for all statuses with the keyword 'camel':
Code Block |
---|
from(" {code} twitter://search?type=direct&keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s] {code} {include:Endpoint See Also}") .to("bean:blah"); |
Searching using a producer with static keywords
Code Block |
---|
from("direct:foo")
.to("twitter://search?keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]");
|
Searching using a producer with dynamic keywords from header
In the bar header we have the keywords we want to search, so we can assign this value to the CamelTwitterKeywords
header.
Code Block |
---|
from("direct:foo")
.setHeader("CamelTwitterKeywords", header("bar"))
.to("twitter://search?consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]");
|
Example
See also the Twitter Websocket Example.
Include Page | ||||
---|---|---|---|---|
|