|
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> URI format
twitter://[endpoint]?[options]
TwitterComponent:The twitter component can be configured with the Twitter account settings which is mandatory to configure before using.
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).
Producer Endpoints:
URI Options
Message header
Message bodyAll message bodies utilize objects provided by the Twitter4J API. Use casesTo 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]); 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"); 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"); Searching using a producer with static keywordsfrom("direct:foo") .to("twitter://search?keywords=camel&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]"); Searching using a producer with dynamic keywords from headerIn 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]"); ExampleSee also the Twitter Websocket Example. See Also |