public class

TwitterConnector

extends Object
implements MuleContextAware
java.lang.Object
   ↳ org.mule.twitter.TwitterConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

A Connector for Twitter which uses twitter4j.

Summary

Fields
private String accessKey
private String accessSecret
private String consumerKey
private String consumerSecret
protected Log logger
private TwitterStream stream
private Twitter twitter
private boolean useSSL
Public Constructors
TwitterConnector()
Public Methods
Place createPlace(String name, String containedWithin, String token, Double latitude, Double longitude, String streetAddress)
Creates a new place at the given latitude and longitude.
Status destroyStatus(long statusId)
Destroys the status specified by the required ID parameter.
void filteredStream(int count, List<Long> userIds, List<String> keywords, SourceCallback callback)
Asynchronously retrieves public statuses that match one or more filter predicates.
void fireshorseStream(int count, SourceCallback callback)
Asynchronously retrieves all public statuses.
Trends getCurrentTrends(boolean excludeHashtags)
Returns the current top 10 trending topics on Twitter.
List<Trends> getDailyTrends(Date date, boolean excludeHashTags)
Returns the top 20 trending topics for each hour in a given day.
Place getGeoDetails(String id)
Find out more details of a place that was returned from the reverseGeoCode operation.
ResponseList<Status> getHomeTimeline(int page, int count, int sinceId)
Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.
ResponseList<Status> getMentions(int page, int count, int sinceId)
Returns the 20 most recent mentions (status containing @username) for the authenticating user.
ResponseList<Status> getPublicTimeline()
Returns the 20 most recent statuses from non-protected users who have set a custom user icon.
ResponseList<User> getRetweetedBy(long statusId, int page, int count, int sinceId)
Show user objects of up to 100 members who retweeted the status.
IDs getRetweetedByIDs(long statusId, int page, int count, int sinceId)
Show user ids of up to 100 users who retweeted the status represented by id
This method calls http://api.twitter.com/1/statuses/:id/retweeted_by/ids.format
ResponseList<Status> getRetweetedByMe(int page, int count, int sinceId)
Returns the 20 most recent retweets posted by the authenticating user.
ResponseList<Status> getRetweetedByUserByScreenName(String screenName, int page, int count, int sinceId)
Returns the 20 most recent retweets posted by the specified user.
ResponseList<Status> getRetweetedByUserByUserId(long userId, int page, int count, int sinceId)
Returns the 20 most recent retweets posted by the specified user.
ResponseList<Status> getRetweetedToMe(int page, int count, int sinceId)
Returns the 20 most recent retweets posted by the authenticating user's friends.
ResponseList<Status> getRetweetedToUserByScreenName(String screenName, int page, int count, int sinceId)
Returns the 20 most recent retweets posted by users the specified user follows.
ResponseList<Status> getRetweetedToUserByUserId(long userId, int page, int count, int sinceId)
Returns the 20 most recent retweets posted by users the specified user follows.
ResponseList<Status> getRetweets(long statusId)
Returns up to 100 of the first retweets of a given tweet.
ResponseList<Status> getRetweetsOfMe(int page, int count, int sinceId)
Returns the 20 most recent tweets of the authenticated user that have been retweeted by others.
Trends getTrends()
Returns the top ten topics that are currently trending on Twitter.
Twitter getTwitterClient()
boolean getUseSSL()
ResponseList<Status> getUserTimeline(int page, int count, int sinceId)
Returns the 20 most recent statuses posted from the authenticating user.
ResponseList<Status> getUserTimelineByScreenName(String screenName, int page, int count, int sinceId)
Returns the 20 most recent statuses posted from the authenticating user.
ResponseList<Status> getUserTimelineByUserId(long userId, int page, int count, int sinceId)
Returns the 20 most recent statuses posted from the authenticating user.
List<Trends> getWeeklyTrends(Date date, boolean excludeHashTags)
Returns the top 30 trending topics for each day in a given week.
void initialise()
void linkStream(int count, SourceCallback callback)
Asynchronously retrieves all statuses containing 'http:' and 'https:'.
String requestAuthorization(String callbackUrl)
Start the OAuth request authorization process.
Status retweetStatus(long statusId)
Retweets a tweet.
ResponseList<Place> reverseGeoCode(Double latitude, Double longitude, String ip)
Search for places (cities and neighborhoods) that can be attached to a statuses/update.
void sampleStream(SourceCallback callback)
Asynchronously retrieves a random sample of all public statuses.
QueryResult search(String query)
Returns tweets that match a specified query.
ResponseList<Place> searchPlaces(Double latitude, Double longitude, String ip)
Search for places that can be attached to a statuses/update.
void setAccessKey(String accessToken)
void setAccessSecret(String accessTokenSecret)
void setConsumerKey(String consumerKey)
void setConsumerSecret(String consumerSecret)
void setMuleContext(MuleContext context)
void setOauthVerifier(String oauthVerifier)
Set the OAuth verifier after it has been retrieved via requestAuthorization.
void setUseSSL(boolean useSSL)
Status showStatus(long id)
Returns a single status, specified by the id parameter below.
User showUser()
Answers user information for the authenticated user
void siteStream(List<Long> userIds, boolean withFollowings, SourceCallback callback_)
Asynchronously retrieves statutes for a set of supplied user's ids.
Status updateStatus(String status, long inReplyTo, GeoLocation geoLocation)
Updates the authenticating user's status.
void userStream(List<String> keywords, SourceCallback callback_)
Retrieves the following user updates notifications:
- New Statuses
- Block/Unblock events
- Follow events
- User profile updates
- Retweets
- List creation/deletion
- List member addition/remotion
- List subscription/unsubscription
- List updates
- Profile updates
Such notifications are represented as org.mule.twitter.UserEvent objects Only one Twitter stream can be consumed using the same credentials.
Protected Methods
Paging getPaging(int page, int count, long sinceId)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mule.api.context.MuleContextAware

Fields

private String accessKey

private String accessSecret

private String consumerKey

private String consumerSecret

protected Log logger

private TwitterStream stream

private Twitter twitter

private boolean useSSL

Public Constructors

public TwitterConnector ()

Public Methods

public Place createPlace (String name, String containedWithin, String token, Double latitude, Double longitude, String streetAddress)

Creates a new place at the given latitude and longitude. <create-place token="#[header:token]" containedWithin="#[header:containedWithin]" name="#[header:placeName]" latitude="#[header:latitude]" longitude="#[header:longitude]" streetAddress="[header:address]"/>

Parameters
name The name a place is known as.
containedWithin The place_id within which the new place can be found. Try and be as close as possible with the containing place. For example, for a room in a building, set the contained_within as the building place_id.
token The token found in the response from geo/similar_places.
latitude The latitude the place is located at.
longitude The longitude the place is located at.
streetAddress optional: This parameter searches for places which have this given street address. There are other well-known, and application specific attributes available. Custom attributes are also permitted. Learn more about Place Attributes.
Returns
  • a new Place
Throws
TwitterException

public Status destroyStatus (long statusId)

Destroys the status specified by the required ID parameter.
Usage note: The authenticating user must be the author of the specified status.
This method calls http://api.twitter.com/1/statuses/destroy

Parameters
statusId The ID of the status to destroy.
Returns
  • the deleted status
Throws
TwitterException when Twitter service or network is unavailable

public void filteredStream (int count, List<Long> userIds, List<String> keywords, SourceCallback callback)

Asynchronously retrieves public statuses that match one or more filter predicates. At least a keyword or userId must be specified. Multiple parameters may be specified. Placing long parameters in the URL may cause the request to be rejected for excessive URL length. The default access level allows up to 200 track keywords and 400 follow userids. Only one Twitter stream can be consumed using the same credentials. As a consequence, only one twitter stream can be consumed per connector instance. <filtered-stream count="5"> <keywords> <keyword>enterprise</keyword> <keyword>integration</keyword> </keywords> </filtered-stream>

Parameters
count the number of previous statuses to stream before transitioning to the live stream.
userIds the user ids to follow
keywords the keywords to track
callback

public void fireshorseStream (int count, SourceCallback callback)

Asynchronously retrieves all public statuses. This stream is not generally available - it requires special permissions and its usage is discouraged by Twitter Only one Twitter stream can be consumed using the same credentials. As a consequence, only one twitter stream can be consumed per connector instance.

Parameters
count
callback

public Trends getCurrentTrends (boolean excludeHashtags)

Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on Twitter Search results page for that topic. <get-current-trends excludeHashtags="true" />

Parameters
excludeHashtags whether all hashtags shoudl be removed from the trends list.
Returns
  • a Trends object
Throws
TwitterException

public List<Trends> getDailyTrends (Date date, boolean excludeHashTags)

Returns the top 20 trending topics for each hour in a given day. <get-daily-trends />

Parameters
date starting date of daily trends. If no date is specified, current date is used
excludeHashTags whether hashtags should be excluded
Returns
  • a list of Trends objects
Throws
TwitterException

public Place getGeoDetails (String id)

Find out more details of a place that was returned from the reverseGeoCode operation. <get-geo-details id="#[header:geocodeId]"/>

Parameters
id The ID of the location to query about.
Returns
  • a Place
Throws
TwitterException

public ResponseList<Status> getHomeTimeline (int page, int count, int sinceId)

Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends. This is the equivalent of /timeline/home on the Web.
Usage note: This home_timeline call is identical to statuses/friends_timeline, except that home_timeline also contains retweets, while statuses/friends_timeline does not for backwards compatibility reasons. In a future version of the API, statuses/friends_timeline will be deprected and replaced by home_timeline.
This method calls http://api.twitter.com/1/statuses/home_timeline

Parameters
page controls pagination. Supports since_id, max_id, count and page parameters.
count
sinceId
Returns
  • list of the home Timeline
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getMentions (int page, int count, int sinceId)

Returns the 20 most recent mentions (status containing @username) for the authenticating user.
This method calls http://api.twitter.com/1/statuses/mentions

Parameters
page
count
sinceId
Returns
  • the 20 most recent replies
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getPublicTimeline ()

Returns the 20 most recent statuses from non-protected users who have set a custom user icon. The public timeline is cached for 60 seconds and requesting it more often than that is unproductive and a waste of resources.
This method calls http://api.twitter.com/1/statuses/public_timeline

Returns
  • list of statuses of the Public Timeline
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<User> getRetweetedBy (long statusId, int page, int count, int sinceId)

Show user objects of up to 100 members who retweeted the status.
This method calls http://api.twitter.com/1/statuses/:id/retweeted_by

Parameters
statusId The ID of the status you want to get retweeters of
page
count
sinceId
Returns
  • the list of users who retweeted your status
Throws
TwitterException when Twitter service or network is unavailable

public IDs getRetweetedByIDs (long statusId, int page, int count, int sinceId)

Show user ids of up to 100 users who retweeted the status represented by id
This method calls http://api.twitter.com/1/statuses/:id/retweeted_by/ids.format

Parameters
statusId The ID of the status you want to get retweeters of
page
count
sinceId
Returns
  • IDs of users who retweeted the stats
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetedByMe (int page, int count, int sinceId)

Returns the 20 most recent retweets posted by the authenticating user.
This method calls http://api.twitter.com/1/statuses/retweeted_by_me

Parameters
page
count
sinceId
Returns
  • the 20 most recent retweets posted by the authenticating user
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetedByUserByScreenName (String screenName, int page, int count, int sinceId)

Returns the 20 most recent retweets posted by the specified user. This method is identical to statuses/retweeted_by_me except you can choose the user to view.
This method has not been finalized and the interface is subject to change in incompatible ways.
This method calls http://api.twitter.com/1/statuses/retweeted_by_user

Parameters
screenName the user to view
page
count
sinceId
Returns
  • the 20 most recent retweets posted by the authenticating user
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetedByUserByUserId (long userId, int page, int count, int sinceId)

Returns the 20 most recent retweets posted by the specified user. This method is identical to statuses/retweeted_by_me except you can choose the user to view.
This method has not been finalized and the interface is subject to change in incompatible ways.
This method calls http://api.twitter.com/1/statuses/retweeted_by_user

Parameters
userId the user to view
page
count
sinceId
Returns
  • the 20 most recent retweets posted by the authenticating user
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetedToMe (int page, int count, int sinceId)

Returns the 20 most recent retweets posted by the authenticating user's friends.
This method calls http://api.twitter.com/1/statuses/retweeted_to_me

Parameters
page
count
sinceId
Returns
  • the 20 most recent retweets posted by the authenticating user's friends.
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetedToUserByScreenName (String screenName, int page, int count, int sinceId)

Returns the 20 most recent retweets posted by users the specified user follows. This method is identical to statuses/retweeted_to_me except you can choose the user to view.
This method has not been finalized and the interface is subject to change in incompatible ways.
This method calls http://api.twitter.com/1/statuses/retweeted_to_user

Parameters
screenName the user to view
page
count
sinceId
Returns
  • the 20 most recent retweets posted by the authenticating user's friends.
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetedToUserByUserId (long userId, int page, int count, int sinceId)

Returns the 20 most recent retweets posted by users the specified user follows. This method is identical to statuses/retweeted_to_me except you can choose the user to view.
This method has not been finalized and the interface is subject to change in incompatible ways.
This method calls http://api.twitter.com/1/statuses/retweeted_to_user

Parameters
userId the user to view
page
count
sinceId
Returns
  • the 20 most recent retweets posted by the authenticating user's friends.
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweets (long statusId)

Returns up to 100 of the first retweets of a given tweet.
This method calls http://api.twitter.com/1/statuses/retweets

Parameters
statusId The numerical ID of the tweet you want the retweets of.
Returns
  • the retweets of a given tweet
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getRetweetsOfMe (int page, int count, int sinceId)

Returns the 20 most recent tweets of the authenticated user that have been retweeted by others.
This method calls http://api.twitter.com/1/statuses/retweets_of_me

Parameters
page
count
sinceId
Returns
  • the 20 most recent tweets of the authenticated user that have been retweeted by others.
Throws
TwitterException when Twitter service or network is unavailable

public Trends getTrends ()

Returns the top ten topics that are currently trending on Twitter. The response includes the time of the request, the name of each trend, and the url to the Twitter Search results page for that topic. <get-trends/>

Returns
  • a Trends object
Throws
TwitterException

public Twitter getTwitterClient ()

public boolean getUseSSL ()

public ResponseList<Status> getUserTimeline (int page, int count, int sinceId)

Returns the 20 most recent statuses posted from the authenticating user. It's also possible to request another user's timeline via the id parameter.
This is the equivalent of the Web / page for your own user, or the profile page for a third party.
For backwards compatibility reasons, retweets are stripped out of the user_timeline when calling in XML or JSON (they appear with 'RT' in RSS and Atom). If you'd like them included, you can merge them in from statuses retweeted_by_me.

This method calls http://api.twitter.com/1/statuses/user_timeline.json

Parameters
page
count
sinceId
Returns
  • list of the user Timeline
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getUserTimelineByScreenName (String screenName, int page, int count, int sinceId)

Returns the 20 most recent statuses posted from the authenticating user. It's also possible to request another user's timeline via the id parameter.
This is the equivalent of the Web / page for your own user, or the profile page for a third party.
For backwards compatibility reasons, retweets are stripped out of the user_timeline when calling in XML or JSON (they appear with 'RT' in RSS and Atom). If you'd like them included, you can merge them in from statuses retweeted_by_me.

This method calls http://api.twitter.com/1/statuses/user_timeline.json

Parameters
screenName specifies the screen name of the user for whom to return the user_timeline
page
count
sinceId
Returns
  • list of the user Timeline
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Status> getUserTimelineByUserId (long userId, int page, int count, int sinceId)

Returns the 20 most recent statuses posted from the authenticating user. It's also possible to request another user's timeline via the id parameter.
This is the equivalent of the Web / page for your own user, or the profile page for a third party.
For backwards compatibility reasons, retweets are stripped out of the user_timeline when calling in XML or JSON (they appear with 'RT' in RSS and Atom). If you'd like them included, you can merge them in from statuses retweeted_by_me.

This method calls http://api.twitter.com/1/statuses/user_timeline.json

Parameters
userId specifies the ID of the user for whom to return the user_timeline
page
count
sinceId
Returns
  • list of the user Timeline
Throws
TwitterException when Twitter service or network is unavailable

public List<Trends> getWeeklyTrends (Date date, boolean excludeHashTags)

Returns the top 30 trending topics for each day in a given week. <get-weekly-trends/>

Parameters
date starting date of daily trends. If no date is specified, current date is used
excludeHashTags if all hashtags should be removed from the trends list.
Returns
  • a list of Trends objects
Throws
TwitterException

public void initialise ()

public void linkStream (int count, SourceCallback callback)

Asynchronously retrieves all statuses containing 'http:' and 'https:'. Like Firehorse, its is not a generally available stream Only one Twitter stream can be consumed using the same credentials. As a consequence, only one twitter stream can be consumed per connector instance.

Parameters
count
callback

public String requestAuthorization (String callbackUrl)

Start the OAuth request authorization process.

Parameters
callbackUrl
Returns
  • The user authorization URL.
Throws
TwitterException

public Status retweetStatus (long statusId)

Retweets a tweet. Returns the original tweet with retweet details embedded.
This method calls http://api.twitter.com/1/statuses/retweet

Parameters
statusId The ID of the status to retweet.
Returns
  • the retweeted status
Throws
TwitterException when Twitter service or network is unavailable

public ResponseList<Place> reverseGeoCode (Double latitude, Double longitude, String ip)

Search for places (cities and neighborhoods) that can be attached to a statuses/update. Given a latitude and a longitude, return a list of all the valid places that can be used as a place_id when updating a status. Conceptually, a query can be made from the user's location, retrieve a list of places, have the user validate the location he or she is at, and then send the ID of this location up with a call to statuses/update.
There are multiple granularities of places that can be returned -- "neighborhoods", "cities", etc. At this time, only United States data is available through this method. <reverse-geo-code ip="#[header:ip]" />

Parameters
latitude latitude coordinate. Mandatory if ip is not specified
longitude longitude coordinate.
ip the ip. Mandatory if coordinates are not specified
Returns
  • a ResponseList of Place
Throws
TwitterException

public void sampleStream (SourceCallback callback)

Asynchronously retrieves a random sample of all public statuses. The sample size and quality varies depending on the account permissions The default access level provides a small proportion of the Firehose. The "Gardenhose" access level provides a proportion more suitable for data mining and research applications that desire a larger proportion to be statistically significant sample. Only one Twitter stream can be consumed using the same credentials. As a consequence, only one twitter stream can be consumed per connector instance. <sample-stream/>

Parameters
callback

public QueryResult search (String query)

Returns tweets that match a specified query.

This method calls http://search.twitter.com/search.json@return

Parameters
query The search query.
Throws
TwitterException

public ResponseList<Place> searchPlaces (Double latitude, Double longitude, String ip)

Search for places that can be attached to a statuses/update. Given a latitude and a longitude pair, or and IP address, this request will return a list of all the valid places that can be used as the place_id when updating a status. <search-places latitude="#[header:latitude]" longitude="#[header:longitude]" />

Parameters
latitude latitude coordinate. Mandatory if ip is not specified
longitude longitude coordinate.
ip the ip. Mandatory if coordinates are not specified
Returns
  • a ResponseList of Place
Throws
TwitterException

public void setAccessKey (String accessToken)

Parameters
accessToken

public void setAccessSecret (String accessTokenSecret)

Parameters
accessTokenSecret

public void setConsumerKey (String consumerKey)

Parameters
consumerKey

public void setConsumerSecret (String consumerSecret)

Parameters
consumerSecret

public void setMuleContext (MuleContext context)

Parameters
context

public void setOauthVerifier (String oauthVerifier)

Set the OAuth verifier after it has been retrieved via requestAuthorization. The resulting access tokens will be logged to the INFO level so the user can reuse them as part of the configuration in the future if desired.

Parameters
oauthVerifier The OAuth verifier code from Twitter.
Throws
TwitterException

public void setUseSSL (boolean useSSL)

Parameters
useSSL

public Status showStatus (long id)

Returns a single status, specified by the id parameter below. The status's author will be returned inline.
This method calls http://api.twitter.com/1/statuses/show

Parameters
id the numerical ID of the status you're trying to retrieve
Returns
  • a single status
Throws
TwitterException when Twitter service or network is unavailable

public User showUser ()

Answers user information for the authenticated user

Returns
  • a User object
Throws
TwitterException

public void siteStream (List<Long> userIds, boolean withFollowings, SourceCallback callback_)

Asynchronously retrieves statutes for a set of supplied user's ids. Site Streams are a beta service, so refer always to latest twitter documentation about them. Only one Twitter stream can be consumed using the same credentials. As a consequence, only one twitter stream can be consumed per connector instance.

Parameters
userIds ids of users to include in the stream
withFollowings withFollowings whether to receive status updates from people following
callback_

public Status updateStatus (String status, long inReplyTo, GeoLocation geoLocation)

Updates the authenticating user's status. A status update with text identical to the authenticating user's text identical to the authenticating user's current status will be ignored to prevent duplicates.
This method calls http://api.twitter.com/1/statuses/update

Parameters
status the text of your status update
inReplyTo
geoLocation
Returns
  • the latest status
Throws
TwitterException when Twitter service or network is unavailable

public void userStream (List<String> keywords, SourceCallback callback_)

Retrieves the following user updates notifications:
- New Statuses
- Block/Unblock events
- Follow events
- User profile updates
- Retweets
- List creation/deletion
- List member addition/remotion
- List subscription/unsubscription
- List updates
- Profile updates
Such notifications are represented as org.mule.twitter.UserEvent objects Only one Twitter stream can be consumed using the same credentials. As a consequence, only one twitter stream can be consumed per connector instance. <user-stream> <keywords> <keyword>enterprise</keyword> <keyword>integration</keyword> </keywords> </user-stream>

Parameters
keywords the keywords to track for new statuses
callback_

Protected Methods

protected Paging getPaging (int page, int count, long sinceId)

Parameters
page
count
sinceId