twitter4j.auth

## Class OAuthAuthorization

- java.lang.Object
- - twitter4j.auth.OAuthAuthorization

All Implemented Interfaces:
  Serializable, Authorization, OAuthSupport

    public class OAuthAuthorization
    extends Object
    implements Authorization, Serializable, OAuthSupport

Author:
  Yusuke Yamamoto - yusuke at mac.com
See Also:
  OAuth Core 1.0a, Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`OAuthAuthorization(Configuration conf)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static String` `encodeParameters(List<HttpParameter> httpParams)`
`static String` `encodeParameters(List<HttpParameter> httpParams, String splitter, boolean quot)`
`boolean` `equals(Object o)`
`List<HttpParameter>` `generateOAuthSignatureHttpParams(String method, String url)`
`String` `getAuthorizationHeader(HttpRequest req)`
`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, String oauthVerifier)` Retrieves an access token associated with the supplied request token and sets userId.
`AccessToken` `getOAuthAccessToken(String oauthVerifier)` Retrieves an access token.
`AccessToken` `getOAuthAccessToken(String screenName, 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(String callbackURL)` Retrieves a request token
`RequestToken` `getOAuthRequestToken(String callbackURL, String xAuthAccessType)` Retrieves a request token
`RequestToken` `getOAuthRequestToken(String callbackURL, String xAuthAccessType, String xAuthMode)` Retrieves a request token
`int` `hashCode()`
`boolean` `isEnabled()` Returns true if authorization credentials are set.
`void` `setOAuthAccessToken(AccessToken accessToken)` Sets the access token
`void` `setOAuthConsumer(String consumerKey, String consumerSecret)` sets the OAuth consumer key and consumer secret
`void` `setOAuthRealm(String realm)` Sets the OAuth realm
`String` `toString()`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### OAuthAuthorization

    public OAuthAuthorization(Configuration conf)

Parameters:
  `conf` - configuration

### Method Detail

#### getAuthorizationHeader

    public String getAuthorizationHeader(HttpRequest req)

Specified by:
  `getAuthorizationHeader` in interface `Authorization`

#### isEnabled

    public boolean isEnabled()

Returns true if authorization credentials are set.

Specified by:
  `isEnabled` in interface `Authorization`
Returns:
  true if authorization credentials are set

#### getOAuthRequestToken

    public RequestToken getOAuthRequestToken()
                                      throws TwitterException

Description copied from interface: `OAuthSupport`
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 | Twitter Developers, OAuth Core 1.0a - 6.1. Obtaining an Unauthorized Request Token, POST oauth/request_token | Twitter Developers

#### getOAuthRequestToken

    public RequestToken getOAuthRequestToken(String callbackURL)
                                      throws TwitterException

Description copied from interface: `OAuthSupport`
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 | Twitter Developers, OAuth Core 1.0a - 6.1. Obtaining an Unauthorized Request Token, POST oauth/request_token | Twitter Developers

#### getOAuthRequestToken

    public RequestToken getOAuthRequestToken(String callbackURL,
                                             String xAuthAccessType)
                                      throws TwitterException

Description copied from interface: `OAuthSupport`
Retrieves a request token

Specified by:
  `getOAuthRequestToken` in interface `OAuthSupport`
Parameters:
  `callbackURL` - callback URL
  `xAuthAccessType` - Overrides the access level an application requests to a users account. Supported values are read or write. This parameter is intended to allow a developer to register a read/write application but also request read only access when appropriate.
Returns:
  generated request token
Throws:
  `TwitterException` - when Twitter service or network is unavailable
See Also:
  OAuth FAQ | Twitter Developers, OAuth Core 1.0a - 6.1. Obtaining an Unauthorized Request Token, POST oauth/request_token | Twitter Developers

#### getOAuthRequestToken

    public RequestToken getOAuthRequestToken(String callbackURL,
                                             String xAuthAccessType,
                                             String xAuthMode)
                                      throws TwitterException

Description copied from interface: `OAuthSupport`
Retrieves a request token

Specified by:
  `getOAuthRequestToken` in interface `OAuthSupport`
Parameters:
  `callbackURL` - callback URL
  `xAuthAccessType` - Overrides the access level an application requests to a users account. Supported values are read or write. This parameter is intended to allow a developer to register a read/write application but also request read only access when appropriate.
  `xAuthMode` - Set to reverse_auth to obtain a special request token to be used in the reverse auth process.
Returns:
  generated request token
Throws:
  `TwitterException` - when Twitter service or network is unavailable
See Also:
  OAuth FAQ | Twitter Developers, OAuth Core 1.0a - 6.1. Obtaining an Unauthorized Request Token, POST oauth/request_token | Twitter Developers

#### getOAuthAccessToken

    public AccessToken getOAuthAccessToken()
                                    throws TwitterException

Description copied from interface: `OAuthSupport`
Returns an access token associated with this instance.
If no access token is associated with this instance, this will retrieve a new access token.

Specified by:
  `getOAuthAccessToken` in interface `OAuthSupport`
Returns:
  access 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?, OAuth Core 1.0a - 6.2. Obtaining User Authorization, POST oauth/access_token | Twitter Developers

#### getOAuthAccessToken

    public AccessToken getOAuthAccessToken(String oauthVerifier)
                                    throws TwitterException

Description copied from interface: `OAuthSupport`
Retrieves an access token.

Specified by:
  `getOAuthAccessToken` in interface `OAuthSupport`
Parameters:
  `oauthVerifier` - OAuth verifier. AKA pin.
Returns:
  access 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?, OAuth Core 1.0a - 6.2. Obtaining User Authorization, POST oauth/access_token | Twitter Developers

#### getOAuthAccessToken

    public AccessToken getOAuthAccessToken(RequestToken requestToken)
                                    throws TwitterException

Description copied from interface: `OAuthSupport`
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:
  `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, POST oauth/access_token | Twitter Developers

#### getOAuthAccessToken

    public AccessToken getOAuthAccessToken(RequestToken requestToken,
                                           String oauthVerifier)
                                    throws TwitterException

Description copied from interface: `OAuthSupport`
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:
  `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, POST oauth/access_token | Twitter Developers

#### getOAuthAccessToken

    public AccessToken getOAuthAccessToken(String screenName,
                                           String password)
                                    throws TwitterException

Description copied from interface: `OAuthSupport`
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?, xAuth | Twitter Developers, POST oauth/access_token | Twitter Developers

#### setOAuthAccessToken

    public void setOAuthAccessToken(AccessToken accessToken)

Description copied from interface: `OAuthSupport`
Sets the access token

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

#### setOAuthRealm

    public void setOAuthRealm(String realm)

Sets the OAuth realm

Parameters:
  `realm` - OAuth realm
Since:
  Twitter 2.1.4

#### generateOAuthSignatureHttpParams

    public List<HttpParameter> generateOAuthSignatureHttpParams(String method,
                                                                String url)

#### encodeParameters

    public static String encodeParameters(List<HttpParameter> httpParams)

Parameters:
  `httpParams` - parameters to be encoded and concatenated
Returns:
  encoded string
See Also:
  OAuth / TestCases, Space encoding - OAuth | Google Groups

#### encodeParameters

    public static String encodeParameters(List<HttpParameter> httpParams,
                                          String splitter,
                                          boolean quot)

#### setOAuthConsumer

    public void setOAuthConsumer(String consumerKey,
                                 String consumerSecret)

Description copied from interface: `OAuthSupport`
sets the OAuth consumer key and consumer secret

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

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`