Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
h2. Twitter
*Available as of Camel 2.10*

The Twitter component enables the most useful features of the Twitter API by encapsulating [Twitter4J|http://twitter4j.org/]. 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.

Twitter 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 Twitter 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:xml}
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-twitter</artifactId>
    <version>${camel-version}</version>
</dependency>
{code}

h3. URI format

{code}
twitter://[endpoint]?[options]
{code}

h3. 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.
{div:class=confluenceTableSmall}
|| Option || Description ||
| consumerKey | The consumer key |
| consumerSecret | The consumer secret |
| accessToken | The access token |
| accessTokenSecret | The access token secret |
{div}

h3. 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}

h3. Producer Endpoints:
{div:class=confluenceTableSmall}
|| Endpoint || Body Type ||
| directmessage | String |
| timeline/user | String |
{div}

h3. URI Options
|| Name || Default Value || Description ||
| type | direct | direct, event, or polling |
| delay | 60 | in seconds |
| consumerKey | {{null}} | Consumer Key. Can also be configured on the {{TwitterComponent}} level instead. |
| consumerSecret | {{null}} | Consumer Secret. Can also be configured on the {{TwitterComponent}} level instead. |
| accessToken | {{null}} | Access Token. Can also be configured on the {{TwitterComponent}} level instead. |
| accessTokenSecret | {{null}} | Access Token Secret. Can also be configured on the {{TwitterComponent}} level instead. |
| user | {{null}} | Username, used for user timeline consumption, direct message production, etc. |
| keywords| {{null}} | 'lat,lon;lat,lon;...' Can be used for streaming/filter |
| userIds| {{null}} | 'username,username...' Can be used for streaming/filter |

h3. Message body

{code}
All message bodies utilize objects provided by the Twitter4J API.
{code}

h3. Maven Dependency:
{code:xml}
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-twitter</artifactId>
    <version>${camel-version}</version>
</dependency>
{code}
 
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 poll, every 5 sec., all statuses on your home timeline:
{code}
twitter://timeline/home?type=polling&delay=5&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]
{code}
h4. To search for all statuses with the keyword 'camel':
{code}
twitter://search?type=direct&keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]
{code}

h3. Example
See also the [Twitter Websocket Example].

{include:Endpoint See Also}
- [Twitter Websocket Example]