org.springframework.social.twitter.api.impl
Class TwitterTemplate

java.lang.Object
  extended by org.springframework.social.twitter.api.impl.TwitterTemplate
All Implemented Interfaces:
TwitterApi

public class TwitterTemplate
extends java.lang.Object
implements TwitterApi

This is the central class for interacting with Twitter.

Most (not all) Twitter operations require OAuth authentication. To perform such operations, TwitterTemplate must be constructed with the minimal amount of information required to sign requests to Twitter's API with an OAuth Authorization header.

There are a few operations, such as searching, that do not require OAuth authentication. In those cases, you may use a TwitterTemplate that is created through the default constructor and without any OAuth details. Attempts to perform secured operations through such an instance, however, will result in BadCredentialsException being thrown.


Constructor Summary
TwitterTemplate()
          Create a new instance of TwitterTemplate.
TwitterTemplate(java.lang.String apiKey, java.lang.String apiSecret, java.lang.String accessToken, java.lang.String accessTokenSecret)
          Create a new instance of TwitterTemplate.
 
Method Summary
 DirectMessageOperations directMessageOperations()
          Returns the portion of the Twitter API containing the direct message operations.
 FriendOperations friendOperations()
          Returns the portion of the Twitter API containing the friends and followers operations.
protected  RestTemplate getRestTemplate()
           
 boolean isAuthorizedForUser()
          Returns true if the TwitterApi is configured to act on behalf of a user (eg., if it was created with OAuth credentials).
 ListOperations listOperations()
          Returns the portion of the Twitter API containing the user list operations.
 SearchOperations searchOperations()
          Returns the portion of the Twitter API containing the search operations.
 TimelineOperations timelineOperations()
          Returns the portion of the Twitter API containing the tweet and timeline operations.
 UserOperations userOperations()
          Returns the portion of the Twitter API containing the user operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwitterTemplate

public TwitterTemplate()
Create a new instance of TwitterTemplate. This constructor creates a new TwitterTemplate able to perform unauthenticated operations against Twitter's API. Some operations, such as search, do not require OAuth authentication. A TwitterTemplate created with this constructor will support those operations. Those operations requiring authentication will throw BadCredentialsException.


TwitterTemplate

public TwitterTemplate(java.lang.String apiKey,
                       java.lang.String apiSecret,
                       java.lang.String accessToken,
                       java.lang.String accessTokenSecret)
Create a new instance of TwitterTemplate.

Parameters:
apiKey - the application's API key
apiSecret - the application's API secret
accessToken - an access token acquired through OAuth authentication with Twitter
accessTokenSecret - an access token secret acquired through OAuth authentication with Twitter
Method Detail

isAuthorizedForUser

public boolean isAuthorizedForUser()
Description copied from interface: TwitterApi
Returns true if the TwitterApi is configured to act on behalf of a user (eg., if it was created with OAuth credentials).

Specified by:
isAuthorizedForUser in interface TwitterApi

timelineOperations

public TimelineOperations timelineOperations()
Description copied from interface: TwitterApi
Returns the portion of the Twitter API containing the tweet and timeline operations.

Specified by:
timelineOperations in interface TwitterApi

friendOperations

public FriendOperations friendOperations()
Description copied from interface: TwitterApi
Returns the portion of the Twitter API containing the friends and followers operations.

Specified by:
friendOperations in interface TwitterApi

listOperations

public ListOperations listOperations()
Description copied from interface: TwitterApi
Returns the portion of the Twitter API containing the user list operations.

Specified by:
listOperations in interface TwitterApi

searchOperations

public SearchOperations searchOperations()
Description copied from interface: TwitterApi
Returns the portion of the Twitter API containing the search operations.

Specified by:
searchOperations in interface TwitterApi

directMessageOperations

public DirectMessageOperations directMessageOperations()
Description copied from interface: TwitterApi
Returns the portion of the Twitter API containing the direct message operations.

Specified by:
directMessageOperations in interface TwitterApi

userOperations

public UserOperations userOperations()
Description copied from interface: TwitterApi
Returns the portion of the Twitter API containing the user operations.

Specified by:
userOperations in interface TwitterApi

getRestTemplate

protected RestTemplate getRestTemplate()