이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 153. Twitter


Twitter

Available as of Camel 2.10
The Twitter component enables the most useful features of the Twitter API by encapsulating Twitter4J. 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:
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-twitter</artifactId>
    <version>${camel-version}</version>
</dependency>
Copy to Clipboard Toggle word wrap

URI format

twitter://endpoint[?options]
Copy to Clipboard Toggle word wrap

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.
Expand
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 (once for each Status).
Expand
Endpoint Context Body Type Notice
directmessage direct, polling twitter4j.DirectMessage
search direct, polling twitter4j.Tweet
streaming/filter event, polling twitter4j.Status
streaming/sample event, polling twitter4j.Status
timeline/home direct, polling twitter4j.Status
timeline/mentions direct, polling twitter4j.Status
timeline/public direct, polling twitter4j.Status @deprecated. Use timeline/home or direct/home instead. Removed from Camel 2.11 onwards.
timeline/retweetsofme direct, polling twitter4j.Status
timeline/user direct, polling twitter4j.Status
trends/daily Camel 2.10.1: direct, polling twitter4j.Status @deprecated. Removed from Camel 2.11 onwards.
trends/weekly Camel 2.10.1: direct, polling twitter4j.Status @deprecated. Removed from Camel 2.11 onwards.

Producer Endpoints:

Expand
Endpoint Body Type
directmessage String
search List<twitter4j.Tweet>
timeline/user String

URI Options

Expand
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.
locations null 'lat,lon;lat,lon;...' Bounding boxes, created by pairs of lat/lons. Can be used for streaming/filter
keywords null 'foo1,foo2,foo3...' Can be used for search and streaming/filter. See Advanced search for keywords syntax for searching with for example OR.
userIds null 'username,username...' Can be used for streaming/filter
filterOld true 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 1 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 null Camel 2.11.0: The lang string ISO_639-1 which will be used for searching
count null Camel 2.11.0: Limiting number of results per page.
numberOfPages 1 Camel 2.11.0: The number of pages result which you want camel-twitter to consume.
httpProxyHost
null
Camel 2.12.3: The http proxy host which can be used for the camel-twitter.
httpProxyPort
null
Camel 2.12.3: The http proxy port which can be used for the camel-twitter.
httpProxyUser
null
Camel 2.12.3: The http proxy user which can be used for the camel-twitter.
httpProxyPassword
null
Camel 2.12.3: The http proxy password which can be used for the camel-twitter.
useSSL
true
Camel 2.12.3: Using the SSL to connect the api.twitter.com if the option is true.

Message header

Expand
Name Description
CamelTwitterKeywords This header is used by the search producer to change the search key words dynamically.
CamelTwitterSearchLanguage Camel 2.11.0: This header can override the option of lang which set the search language for the search endpoint dynamically
CamelTwitterCount Camel 2.11.0 This header can override the option of count which sets the max twitters that will be returned.
CamelTwitterNumberOfPages Camel 2.11.0 This header can converrid the option of numberOfPages which sets how many pages we want to twitter returns.

Message body

All message bodies utilize objects provided by the Twitter4J API.

To create a status update within your Twitter profile, send this producer a String body.

from("direct:foo")
  .to("twitter://timeline/user?consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]);
Copy to Clipboard Toggle word wrap

To poll, every 5 sec., all statuses on your home timeline:

from("twitter://timeline/home?type=polling&delay=5&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]")
  .to("bean:blah");
Copy to Clipboard Toggle word wrap

To search for all statuses with the keyword 'camel':

from("twitter://search?type=direct&keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]")
  .to("bean:blah");
Copy to Clipboard Toggle word wrap

Searching using a producer with static keywords

from("direct:foo")
  .to("twitter://search?keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]");
Copy to Clipboard Toggle word wrap

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.
from("direct:foo")
  .setHeader("CamelTwitterKeywords", header("bar"))
  .to("twitter://search?consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]");
Copy to Clipboard Toggle word wrap

Example

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat