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

Chapter 325. Twitter Components


Available as of Camel version 2.10

The camel-twitter consists of 4 components:

The Twitter components enable 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>

325.1. 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).

EndpointContextBody TypeNotice

twitter-directmessage

direct, polling

twitter4j.DirectMessage

 

twitter-search

direct, polling

twitter4j.Status

 

twitter-streaming

event, polling

twitter4j.Status

 

twitter-timeline

direct, polling

twitter4j.Status

 

325.2. Producer endpoints

EndpointBody TypeNotice

twitter-directmessage

String

 

twitter-search

List<twitter4j.Status>

 

twitter-timeline

String

Only 'user' timelineType is supported for producer

325.3. Message headers

NameDescription

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 override the option of numberOfPages which sets how many pages we want to twitter returns.

325.4. Message body

All message bodies utilize objects provided by the Twitter4J API.

325.5. Use cases

Note

API Rate Limits: 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.

325.5.1. 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]);

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

from("twitter-timeline://home?type=polling&delay=60&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]")
  .to("bean:blah");

325.5.3. To search for all statuses with the keyword 'camel' only once:

from("twitter-search://foo?type=polling&keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]")
  .to("bean:blah");

325.5.4. Searching using a producer with static keywords:

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

325.5.5. 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://foo?consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]");

325.6. Example

See also the Twitter Websocket Example.

325.7. See Also

  • Configuring Camel
  • Component
  • Endpoint
  • Getting Started
  • Twitter Websocket Example
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

© 2024 Red Hat, Inc.