camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Twitter
Date Fri, 10 May 2013 11:58:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Twitter">Twitter</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| user | {{null}} | Username, used
for user timeline consumption, direct message production, etc. | <br>| locations| {{null}}
| &#39;lat,lon;lat,lon;...&#39; Bounding boxes, created by pairs of lat/lons.  Can
be used for streaming/filter | <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|
keywords| {{null}} | &#39;foo1,foo2,foo3...&#39; Can be used for search and streaming/filter
| <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
keywords| {{null}} | &#39;foo1,foo2,foo3...&#39; Can be used for search and streaming/filter.
See [Advanced search|https://support.twitter.com/articles/71577-using-advanced-search] for
keywords syntax for searching with for example OR. | <br></td></tr>
            <tr><td class="diff-unchanged" >| userIds| {{null}} | &#39;username,username...&#39;
Can be used for streaming/filter | <br>| 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 | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Twitter-Twitter"></a>Twitter</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>The Twitter component enables the most useful features of the Twitter API by encapsulating
<a href="http://twitter4j.org/" class="external-link" rel="nofollow">Twitter4J</a>.
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.</p>

<p>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 <a href="https://dev.twitter.com/apps/new" class="external-link" rel="nofollow">https://dev.twitter.com/apps/new</a>
and grant the application access to your account. Finally, generate your access token and
secret.</p>

<p>Maven users will need to add the following dependency to their pom.xml for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-twitter<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>${camel-version}<span
class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="Twitter-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
twitter:<span class="code-comment">//[endpoint]?[options]</span>
</pre>
</div></div>

<h3><a name="Twitter-TwitterComponent%3A"></a>TwitterComponent:</h3>

<p>The twitter component can be configured with the Twitter account settings which is
mandatory to configure before using.<br/>
You can also configure these options directly in the endpoint.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> consumerKey </td>
<td class='confluenceTd'> The consumer key </td>
</tr>
<tr>
<td class='confluenceTd'> consumerSecret </td>
<td class='confluenceTd'> The consumer secret </td>
</tr>
<tr>
<td class='confluenceTd'> accessToken </td>
<td class='confluenceTd'> The access token </td>
</tr>
<tr>
<td class='confluenceTd'> accessTokenSecret </td>
<td class='confluenceTd'> The access token secret </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Twitter-ConsumerEndpoints%3A"></a>Consumer Endpoints:</h3>
<p>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).</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Endpoint </th>
<th class='confluenceTh'> Context </th>
<th class='confluenceTh'> Body Type </th>
<th class='confluenceTh'> Notice </th>
</tr>
<tr>
<td class='confluenceTd'> directmessage </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.DirectMessage </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> search </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.Tweet </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> streaming/filter </td>
<td class='confluenceTd'> event, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> streaming/sample </td>
<td class='confluenceTd'> event, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> timeline/home </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> timeline/mentions </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> timeline/public </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'> @deprecated. Use timeline/home or direct/home instead. Removed
from <b>Camel 2.11</b> onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> timeline/retweetsofme </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> timeline/user </td>
<td class='confluenceTd'> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> trends/daily </td>
<td class='confluenceTd'> <b>Camel 2.10.1:</b> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'> @deprecated. Removed from Camel 2.11 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> trends/weekly </td>
<td class='confluenceTd'> <b>Camel 2.10.1:</b> direct, polling </td>
<td class='confluenceTd'> twitter4j.Status </td>
<td class='confluenceTd'> @deprecated. Removed from Camel 2.11 onwards. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Twitter-ProducerEndpoints%3A"></a>Producer Endpoints:</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Endpoint </th>
<th class='confluenceTh'> Body Type </th>
</tr>
<tr>
<td class='confluenceTd'> directmessage </td>
<td class='confluenceTd'> String </td>
</tr>
<tr>
<td class='confluenceTd'> search </td>
<td class='confluenceTd'> List&lt;twitter4j.Tweet&gt; </td>
</tr>
<tr>
<td class='confluenceTd'> timeline/user </td>
<td class='confluenceTd'> String </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Twitter-URIOptions"></a>URI Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> type </td>
<td class='confluenceTd'> <tt>direct</tt> </td>
<td class='confluenceTd'> direct, event, or polling </td>
</tr>
<tr>
<td class='confluenceTd'> delay </td>
<td class='confluenceTd'> <tt>60</tt> </td>
<td class='confluenceTd'> in seconds </td>
</tr>
<tr>
<td class='confluenceTd'> consumerKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Key. Can also be configured on the <tt>TwitterComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> consumerSecret </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Secret. Can also be configured on the <tt>TwitterComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> accessToken </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Access Token. Can also be configured on the <tt>TwitterComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> accessTokenSecret </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Access Token Secret. Can also be configured on the <tt>TwitterComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> user </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Username, used for user timeline consumption, direct message
production, etc. </td>
</tr>
<tr>
<td class='confluenceTd'> locations</td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> 'lat,lon;lat,lon;...' Bounding boxes, created by pairs of
lat/lons.  Can be used for streaming/filter </td>
</tr>
<tr>
<td class='confluenceTd'> keywords</td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> 'foo1,foo2,foo3...' Can be used for search and streaming/filter.
See <a href="https://support.twitter.com/articles/71577-using-advanced-search" class="external-link"
rel="nofollow">Advanced search</a> for keywords syntax for searching with for example
OR. </td>
</tr>
<tr>
<td class='confluenceTd'> userIds</td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> 'username,username...' Can be used for streaming/filter </td>
</tr>
<tr>
<td class='confluenceTd'> filterOld </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Filter out old tweets, that has previously been polled. This
state is stored in memory only, and based on last tweet id. <b>Since Camel 2.11.0</b>
The search producer supports this option </td>
</tr>
<tr>
<td class='confluenceTd'> sinceId </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.0:</b> 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.</td>
</tr>
<tr>
<td class='confluenceTd'> lang </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.0:</b> The lang string <a href="http://en.wikipedia.org/wiki/ISO_639-1"
class="external-link" rel="nofollow">ISO_639-1</a> which will be used for searching
</td>
</tr>
<tr>
<td class='confluenceTd'> count </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.0:</b> Limiting number of results
per page. </td>
</tr>
<tr>
<td class='confluenceTd'> numberOfPages </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.0:</b> The number of pages result
which you want camel-twitter to consume. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Twitter-Messageheader"></a>Message header</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'><tt>CamelTwitterKeywords</tt></td>
<td class='confluenceTd'>This header is used by the search producer to change the search
key words dynamically.</td>
</tr>
<tr>
<td class='confluenceTd'><tt>CamelTwitterSearchLanguage</tt></td>
<td class='confluenceTd'> <b>Camel 2.11.0:</b> This header can override
the option of <tt>lang</tt> which set the search language for the search endpoint
dynamically</td>
</tr>
<tr>
<td class='confluenceTd'><tt>CamelTwitterCount</tt></td>
<td class='confluenceTd'><b>Camel 2.11.0</b> This header can override the
option of <tt>count</tt> which sets the max twitters that will be returned.</td>
</tr>
<tr>
<td class='confluenceTd'><tt>CamelTwitterNumberOfPages</tt></td>
<td class='confluenceTd'><b>Camel 2.11.0</b> This header can converrid the
option of <tt>numberOfPages</tt> which sets how many pages we want to twitter
returns.</td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Twitter-Messagebody"></a>Message body</h3>
<p>All message bodies utilize objects provided by the Twitter4J API.</p>


<h3><a name="Twitter-Usecases"></a>Use cases</h3>

<h4><a name="Twitter-TocreateastatusupdatewithinyourTwitterprofile%2CsendthisproduceraStringbody."></a>To
create a status update within your Twitter profile, send this producer a String body.</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:foo"</span>)
  .to("twitter:<span class="code-comment">//timeline/user?consumerKey=[s]&amp;consumerSecret=[s]&amp;accessToken=[s]&amp;accessTokenSecret=[s]);</span>
</pre>
</div></div>
<h4><a name="Twitter-Topoll%2Cevery5sec.%2Callstatusesonyourhometimeline%3A"></a>To
poll, every 5 sec., all statuses on your home timeline:</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"twitter:<span class="code-comment">//timeline/home?type=polling&amp;delay=5&amp;consumerKey=[s]&amp;consumerSecret=[s]&amp;accessToken=[s]&amp;accessTokenSecret=[s]"</span>)
</span>  .to(<span class="code-quote">"bean:blah"</span>);
</pre>
</div></div>
<h4><a name="Twitter-Tosearchforallstatuseswiththekeyword%27camel%27%3A"></a>To
search for all statuses with the keyword 'camel':</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"twitter:<span class="code-comment">//search?type=direct&amp;keywords=camel&amp;consumerKey=[s]&amp;consumerSecret=[s]&amp;accessToken=[s]&amp;accessTokenSecret=[s]"</span>)
</span>  .to(<span class="code-quote">"bean:blah"</span>);
</pre>
</div></div>

<h4><a name="Twitter-Searchingusingaproducerwithstatickeywords"></a>Searching
using a producer with static keywords</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:foo"</span>)
  .to(<span class="code-quote">"twitter:<span class="code-comment">//search?keywords=camel&amp;consumerKey=[s]&amp;consumerSecret=[s]&amp;accessToken=[s]&amp;accessTokenSecret=[s]"</span>);</span>
</pre>
</div></div>

<h4><a name="Twitter-Searchingusingaproducerwithdynamickeywordsfromheader"></a>Searching
using a producer with dynamic keywords from header</h4>
<p>In the bar header we have the keywords we want to search, so we can assign this value
to the <tt>CamelTwitterKeywords</tt> header.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:foo"</span>)
  .setHeader(<span class="code-quote">"CamelTwitterKeywords"</span>, header(<span
class="code-quote">"bar"</span>))
  .to(<span class="code-quote">"twitter:<span class="code-comment">//search?consumerKey=[s]&amp;consumerSecret=[s]&amp;accessToken=[s]&amp;accessTokenSecret=[s]"</span>);</span>
</pre>
</div></div>

<h3><a name="Twitter-Example"></a>Example</h3>
<p>See also the <a href="/confluence/display/CAMEL/Twitter+Websocket+Example" title="Twitter
Websocket Example">Twitter Websocket Example</a>.</p>

<h3><a name="Twitter-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Twitter+Websocket+Example" title="Twitter
Websocket Example">Twitter Websocket Example</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Twitter">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27837225&revisedVersion=16&originalVersion=15">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Twitter?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message