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

java.lang.Object
  extended by org.springframework.social.oauth1.AbstractOAuth1ApiBinding
      extended by org.springframework.social.twitter.api.impl.TwitterTemplate
All Implemented Interfaces:
org.springframework.social.ApiBinding, Twitter

public class TwitterTemplate
extends org.springframework.social.oauth1.AbstractOAuth1ApiBinding
implements Twitter

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.


Constructor Summary
TwitterTemplate(String clientToken)
          Create a new instance of TwitterTemplate.
TwitterTemplate(String consumerKey, String consumerSecret)
          Create a new instance of TwitterTemplate.
TwitterTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret)
          Create a new instance of TwitterTemplate.
 
Method Summary
 BlockOperations blockOperations()
          Returns the portion of the Twitter API containing the block operations.
protected  void configureRestTemplate(RestTemplate restTemplate)
           
 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.
 GeoOperations geoOperations()
          Returns the portion of the Twitter API containing the geo location operations.
protected  FormHttpMessageConverter getFormMessageConverter()
           
protected  MappingJackson2HttpMessageConverter getJsonMessageConverter()
           
 RestTemplate getRestTemplate()
           
 ListOperations listOperations()
          Returns the portion of the Twitter API containing the user list operations.
 RestOperations restOperations()
          Returns the underlying RestOperations object allowing for consumption of Twitter endpoints that may not be otherwise covered by the API binding.
 SearchOperations searchOperations()
          Returns the portion of the Twitter API containing the search operations.
 StreamingOperations streamingOperations()
          Returns the portion of the Twitter API containing the streaming 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 org.springframework.social.oauth1.AbstractOAuth1ApiBinding
getByteArrayMessageConverter, getMessageConverters, isAuthorized, setRequestFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.social.ApiBinding
isAuthorized
 

Constructor Detail

TwitterTemplate

public TwitterTemplate(String consumerKey,
                       String consumerSecret,
                       String accessToken,
                       String accessTokenSecret)
Create a new instance of TwitterTemplate.

Parameters:
consumerKey - the application's API key
consumerSecret - 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

TwitterTemplate

public TwitterTemplate(String clientToken)
Create a new instance of TwitterTemplate. This instance of TwitterTemplate is limited to only performing operations requiring client authorization. For instance, you can use it to search Twitter, but you cannot use it to post a status update. The access token you use here must be obtained via OAuth 2 Client Credentials Grant. See OAuth2Operations.authenticateClient().

Parameters:
clientToken - an access token obtained through OAuth 2 client credentials grant with Twitter.

TwitterTemplate

public TwitterTemplate(String consumerKey,
                       String consumerSecret)
Create a new instance of TwitterTemplate. This instance of TwitterTemplate is limited to only performing operations requiring client authorization. For instance, you can use it to search Twitter, but you cannot use it to post a status update. The client credentials given here are used to obtain a client access token via OAuth 2 Client Credentials Grant. See OAuth2Operations.authenticateClient().

Parameters:
consumerKey - the application's API key
consumerSecret - the application's API secret
Method Detail

timelineOperations

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

Specified by:
timelineOperations in interface Twitter

friendOperations

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

Specified by:
friendOperations in interface Twitter

listOperations

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

Specified by:
listOperations in interface Twitter

searchOperations

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

Specified by:
searchOperations in interface Twitter

directMessageOperations

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

Specified by:
directMessageOperations in interface Twitter

userOperations

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

Specified by:
userOperations in interface Twitter

blockOperations

public BlockOperations blockOperations()
Description copied from interface: Twitter
Returns the portion of the Twitter API containing the block operations.

Specified by:
blockOperations in interface Twitter

geoOperations

public GeoOperations geoOperations()
Description copied from interface: Twitter
Returns the portion of the Twitter API containing the geo location operations.

Specified by:
geoOperations in interface Twitter

streamingOperations

public StreamingOperations streamingOperations()
Description copied from interface: Twitter
Returns the portion of the Twitter API containing the streaming operations.

Specified by:
streamingOperations in interface Twitter

restOperations

public RestOperations restOperations()
Description copied from interface: Twitter
Returns the underlying RestOperations object allowing for consumption of Twitter endpoints that may not be otherwise covered by the API binding. The RestOperations object returned is configured to include an OAuth "Authorization" header on all requests.

Specified by:
restOperations in interface Twitter

getRestTemplate

public RestTemplate getRestTemplate()
Overrides:
getRestTemplate in class org.springframework.social.oauth1.AbstractOAuth1ApiBinding

getJsonMessageConverter

protected MappingJackson2HttpMessageConverter getJsonMessageConverter()
Overrides:
getJsonMessageConverter in class org.springframework.social.oauth1.AbstractOAuth1ApiBinding

getFormMessageConverter

protected FormHttpMessageConverter getFormMessageConverter()
Overrides:
getFormMessageConverter in class org.springframework.social.oauth1.AbstractOAuth1ApiBinding

configureRestTemplate

protected void configureRestTemplate(RestTemplate restTemplate)
Overrides:
configureRestTemplate in class org.springframework.social.oauth1.AbstractOAuth1ApiBinding