twitter4j
Class TwitterBaseImpl

java.lang.Object
  extended by twitter4j.TwitterBaseImpl
All Implemented Interfaces:
java.io.Serializable, OAuthSupport, twitter4j.internal.http.HttpResponseListener
Direct Known Subclasses:
AsyncTwitterImpl, TwitterImpl, TwitterStreamImpl

abstract class TwitterBaseImpl
extends java.lang.Object
implements java.io.Serializable, OAuthSupport, twitter4j.internal.http.HttpResponseListener

Base class of Twitter / AsyncTwitter / TwitterStream supports OAuth.

Author:
Yusuke Yamamoto - yusuke at mac.com

Field Summary
protected  Authorization auth
           
protected  Configuration conf
           
protected  twitter4j.internal.http.HttpClientWrapper http
           
protected  long id
           
private  java.util.List<RateLimitStatusListener> rateLimitStatusListeners
           
protected  java.lang.String screenName
           
private static long serialVersionUID
           
 
Constructor Summary
TwitterBaseImpl(Configuration conf)
           
TwitterBaseImpl(Configuration conf, Authorization auth)
           
 
Method Summary
 void addRateLimitStatusListener(RateLimitStatusListener listener)
          
protected  void ensureAuthorizationEnabled()
           
protected  void ensureOAuthEnabled()
           
 boolean equals(java.lang.Object o)
           
protected  User fillInIDAndScreenName()
           
 Authorization getAuthorization()
          
 Configuration getConfiguration()
          
 long getId()
          
private  OAuthSupport getOAuth()
           
 AccessToken getOAuthAccessToken()
          Returns an access token associated with this instance.
If no access token is associated with this instance, this will retrieve a new access token.
 AccessToken getOAuthAccessToken(RequestToken requestToken)
          Retrieves an access token associated with the supplied request token and sets userId.
 AccessToken getOAuthAccessToken(RequestToken requestToken, java.lang.String oauthVerifier)
          Retrieves an access token associated with the supplied request token and sets userId.
 AccessToken getOAuthAccessToken(java.lang.String oauthVerifier)
          Retrieves an access token.
 AccessToken getOAuthAccessToken(java.lang.String screenName, java.lang.String password)
          Retrieves an access token associated with the supplied screen name and password using xAuth.
In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api@twitter.com — all other applications will receive an HTTP 401 error.
 RequestToken getOAuthRequestToken()
          Retrieves a request token
 RequestToken getOAuthRequestToken(java.lang.String callbackUrl)
          Retrieves a request token
 java.lang.String getScreenName()
          
 int hashCode()
           
 void httpResponseReceived(twitter4j.internal.http.HttpResponseEvent event)
           
private  void init()
           
private  void readObject(java.io.ObjectInputStream stream)
           
 void setOAuthAccessToken(AccessToken accessToken)
          Sets the access token
 void setOAuthConsumer(java.lang.String consumerKey, java.lang.String consumerSecret)
          sets the OAuth consumer key and consumer secret
 void shutdown()
          
 java.lang.String toString()
           
private  void writeObject(java.io.ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

conf

protected Configuration conf

screenName

protected transient java.lang.String screenName

id

protected transient long id

http

protected transient twitter4j.internal.http.HttpClientWrapper http

rateLimitStatusListeners

private java.util.List<RateLimitStatusListener> rateLimitStatusListeners

auth

protected Authorization auth

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

TwitterBaseImpl

TwitterBaseImpl(Configuration conf)

TwitterBaseImpl

TwitterBaseImpl(Configuration conf,
                Authorization auth)
Method Detail

init

private void init()

getScreenName

public java.lang.String getScreenName()
                               throws TwitterException,
                                      java.lang.IllegalStateException

Throws:
TwitterException
java.lang.IllegalStateException

getId

public long getId()
           throws TwitterException,
                  java.lang.IllegalStateException

Throws:
TwitterException
java.lang.IllegalStateException

fillInIDAndScreenName

protected User fillInIDAndScreenName()
                              throws TwitterException
Throws:
TwitterException

addRateLimitStatusListener

public void addRateLimitStatusListener(RateLimitStatusListener listener)


httpResponseReceived

public void httpResponseReceived(twitter4j.internal.http.HttpResponseEvent event)
Specified by:
httpResponseReceived in interface twitter4j.internal.http.HttpResponseListener

getAuthorization

public final Authorization getAuthorization()


getConfiguration

public Configuration getConfiguration()


shutdown

public void shutdown()


ensureAuthorizationEnabled

protected final void ensureAuthorizationEnabled()

ensureOAuthEnabled

protected final void ensureOAuthEnabled()

writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException
Throws:
java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream stream)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

setOAuthConsumer

public void setOAuthConsumer(java.lang.String consumerKey,
                             java.lang.String consumerSecret)
sets the OAuth consumer key and consumer secret

Specified by:
setOAuthConsumer in interface OAuthSupport
Parameters:
consumerKey - OAuth consumer key
consumerSecret - OAuth consumer secret

getOAuthRequestToken

public RequestToken getOAuthRequestToken()
                                  throws TwitterException
Retrieves a request token

Specified by:
getOAuthRequestToken in interface OAuthSupport
Returns:
generated request token.
Throws:
TwitterException - when Twitter service or network is unavailable
See Also:
OAuth FAQ | dev.twitter.com, OAuth Core 1.0a - 6.1. Obtaining an Unauthorized Request Token

getOAuthRequestToken

public RequestToken getOAuthRequestToken(java.lang.String callbackUrl)
                                  throws TwitterException
Retrieves a request token

Specified by:
getOAuthRequestToken in interface OAuthSupport
Parameters:
callbackUrl - callback URL
Returns:
generated request token
Throws:
TwitterException - when Twitter service or network is unavailable
See Also:
OAuth FAQ | dev.twitter.com, OAuth Core 1.0a - 6.1. Obtaining an Unauthorized Request Token

getOAuthAccessToken

public AccessToken getOAuthAccessToken()
                                throws TwitterException
Returns an access token associated with this instance.
If no access token is associated with this instance, this will retrieve a new access token. Basic authenticated instance of this class will try acquiring an AccessToken using xAuth.
In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api@twitter.com all other applications will receive an HTTP 401 error. Web-based applications will not be granted access, except on a temporary basis for when they are converting from basic-authentication support to full OAuth support.
Storage of Twitter usernames and passwords is forbidden. By using xAuth, you are required to store only access tokens and access token secrets. If the access token expires or is expunged by a user, you must ask for their login and password again before exchanging the credentials for an access token.

Specified by:
getOAuthAccessToken in interface OAuthSupport
Returns:
access token
Throws:
TwitterException - When Twitter service or network is unavailable, when the user has not authorized, or when the client application is not permitted to use xAuth
See Also:
Twitter REST API Method: oauth access_token for xAuth

getOAuthAccessToken

public AccessToken getOAuthAccessToken(java.lang.String oauthVerifier)
                                throws TwitterException
Retrieves an access token.

Specified by:
getOAuthAccessToken in interface OAuthSupport
Parameters:
oauthVerifier - OAuth verifier. AKA pin.
Returns:
access token
Throws:
java.lang.IllegalStateException - when AccessToken has already been retrieved or set
TwitterException - when Twitter service or network is unavailable, or the user has not authorized
See Also:
OAuth FAQ | dev.twitter.com - How long does an access token last?, OAuth Core 1.0a - 6.2. Obtaining User Authorization

getOAuthAccessToken

public AccessToken getOAuthAccessToken(RequestToken requestToken)
                                throws TwitterException
Retrieves an access token associated with the supplied request token and sets userId.

Specified by:
getOAuthAccessToken in interface OAuthSupport
Parameters:
requestToken - the request token
Returns:
access token associated with the supplied request token.
Throws:
java.lang.IllegalStateException - when AccessToken has already been retrieved or set
TwitterException - when Twitter service or network is unavailable, or the user has not authorized
See Also:
OAuth FAQ | dev.twitter.com - How long does an access token last?, OAuth Core 1.0a - 6.2. Obtaining User Authorization

getOAuthAccessToken

public AccessToken getOAuthAccessToken(RequestToken requestToken,
                                       java.lang.String oauthVerifier)
                                throws TwitterException
Retrieves an access token associated with the supplied request token and sets userId.

Specified by:
getOAuthAccessToken in interface OAuthSupport
Parameters:
requestToken - the request token
oauthVerifier - OAuth verifier. AKA pin.
Returns:
access token associated with the supplied request token.
Throws:
java.lang.IllegalStateException - when AccessToken has already been retrieved or set
TwitterException - when Twitter service or network is unavailable, or the user has not authorized
See Also:
OAuth Core 1.0a - 6.2. Obtaining User Authorization

setOAuthAccessToken

public void setOAuthAccessToken(AccessToken accessToken)
Sets the access token

Specified by:
setOAuthAccessToken in interface OAuthSupport
Parameters:
accessToken - accessToken

getOAuthAccessToken

public AccessToken getOAuthAccessToken(java.lang.String screenName,
                                       java.lang.String password)
                                throws TwitterException
Retrieves an access token associated with the supplied screen name and password using xAuth.
In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api@twitter.com — all other applications will receive an HTTP 401 error. Web-based applications will not be granted access, except on a temporary basis for when they are converting from basic-authentication support to full OAuth support.
Storage of Twitter usernames and passwords is forbidden. By using xAuth, you are required to store only access tokens and access token secrets. If the access token expires or is expunged by a user, you must ask for their login and password again before exchanging the credentials for an access token.

Specified by:
getOAuthAccessToken in interface OAuthSupport
Parameters:
screenName - the screen name
password - the password
Returns:
access token associated with the supplied request token.
Throws:
TwitterException - when Twitter service or network is unavailable, or the user has not authorized
See Also:
OAuth FAQ | dev.twitter.com - How long does an access token last?, Twitter REST API Method: oauth access_token for xAuth

getOAuth

private OAuthSupport getOAuth()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object