Twitter Adapter
Spring Integration provides support for interacting with Twitter. With the Twitter adapters you can both
receive and send Twitter messages. You can also perform a Twitter search based on a schedule and publish
the search results within Messages.
Twitter Template
As mentioned above, Spring Integration relies upon Spring Social, and that library provides an implementation of the template
pattern, o.s.social.twitter.api.impl.TwitterTemplate to interact with Twitter.
For anonymous operations (e.g., search), you don't have to define an instance of TwitterTemplate explicitly,
since a default instance will be created and injected into the endpoint. However, for authenticated operations
(update status, send direct message, etc.), you must configure a TwitterTemplate as a bean and
inject it explicitly into the endpoint, because the authentication configuration is required.
Below is a sample configuration of TwitterTemplate:
]]>
The values above are not real.
As you can see from the configuration above, all we need to do is to provide
OAuth attributes as constructor arguments. The values would be those you obtained in the previous step.
The order of constructor arguments is: 1) consumerKey, 2) consumerSecret,
3) accessToken, and 4) accessTokenSecret.
A more practical way to manage OAuth connection attributes would be via Spring's property placeholder support by simply
creating a property file (e.g., oauth.properties):
Then, you can configure a property-placeholder to point to the above property file:
]]>