com.vic.twitter
Class VICTwitter

java.lang.Object
  extended by com.vic.twitter.VICTwitter

public class VICTwitter
extends java.lang.Object

This class helps java developers easily to interact with Twitter over Twitter APIs. VICTwitter can be easily implemented with web applications as part of single sign on (SSO), as well as java applications. VICTwitter uses OAuth HTTP Authorization Scheme.


This class should be used along with twitter4j

Authenticating with OAuth

OAuth authentication is the process in which Users grant access to their Protected Resources without sharing their credentials with the Consumer. OAuth uses Tokens generated by the Service Provider instead of the User’s credentials in Protected Resources requests. The process uses two Token types:
Request Token: Used by the Consumer to ask the User to authorize access to the Protected Resources. The User-authorized Request Token is exchanged for an Access Token, MUST only be used once, and MUST NOT be used for any other purpose. It is RECOMMENDED that Request Tokens have a limited lifetime.
Access Token: Used by the Consumer to access the Protected Resources on behalf of the User. Access Tokens MAY limit access to certain Protected Resources, and MAY have a limited lifetime. Service Providers SHOULD allow Users to revoke Access Tokens. Only the Access Token SHALL be used to access the Protect Resources.
OAuth Authentication is done in three steps:
1) The Consumer obtains an unauthorized Request Token.
2) The User authorizes the Request Token.
3) The Consumer exchanges the Request Token for an Access Token.

Version:
1.0
Author:
VIC Consulting



Field Summary
static int TOKEN
           
static int TOKEN_SECRET
           
 
Constructor Summary
VICTwitter(java.lang.String consumKey, java.lang.String consumSecret)
           
VICTwitter(java.lang.String consumKey, java.lang.String consumSecret, twitter4j.http.AccessToken accessToken)
           
 
Method Summary
 twitter4j.User follow(java.lang.String screenName)
          Follow another Twitter user.
 twitter4j.http.AccessToken getAccessToken()
          Returns an access token associated with this instance.
 twitter4j.http.AccessToken getAccessToken(java.lang.String token, java.lang.String tokenSecret)
          Returns an access token associated with this instance.
 twitter4j.http.AccessToken getAccessToken(twitter4j.Twitter vTwitter)
          Returns an access token associated with this instance.
 java.lang.String[] getAccessTokenDetails()
          Returns an access token and password.
 java.lang.String getAuthenticationURL()
          Get Twitter Authentication (OAuth protocol) URL.
 java.lang.String getAuthenticationURL(twitter4j.http.RequestToken requestToken)
          Get Twitter Authentication (OAuth protocol) URL
 java.lang.String getConsumerKey()
           
 java.lang.String getConsumerSecret()
           
 int getHourlyLimit(twitter4j.RateLimitStatus rateLimitSts)
          Get Twitter user hourly API call limitations.
 twitter4j.http.RequestToken getOAuthRequestToken()
          Get Twitter Request token
 twitter4j.RateLimitStatus getRateLimitStatus()
          Get Twitter user Rate Limit details.
 int getRemainingHits(twitter4j.RateLimitStatus rateLimitSts)
          Get Twitter user remaining API call limit.
 int getSecondsUntilReset(twitter4j.RateLimitStatus rateLimitSts)
          Time in seconds, left for reset hourly limit.
 twitter4j.User getTwiterUser()
          Returns Twitter user representation of already authentication session (see loadTwiterUser).
 twitter4j.Twitter getTwitter4j()
           
 java.lang.String getUserDescription(twitter4j.User u)
          Get Twitter user description.
 java.lang.String[] getUserFollowers(int limit)
          Get Twitter user followers.
 java.lang.String[] getUserFriends(int limit)
          Get Twitter user friends.
 java.lang.String getUserName(twitter4j.User u)
          Get Twitter user name.
 java.lang.String getUserScreenName(twitter4j.User u)
          Get Twitter user screen name.
 twitter4j.User loadTwiterUser()
          Returns Twitter user representation if authentication was successful.
 void sendDirectMessage(java.lang.String screenName, java.lang.String text)
          Send direct message to another twitter user.
 twitter4j.User showUser(int userId)
          Returns given Twitter user (id) representation.
 twitter4j.User showUser(java.lang.String screenName)
          Returns given Twitter user (screenName) representation.
 void shutdown()
          Release all recourse associated with this session.
 void updateStatus(java.lang.String text)
          Update status of authenticated Twitter user.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOKEN

public static final int TOKEN
See Also:
Constant Field Values

TOKEN_SECRET

public static final int TOKEN_SECRET
See Also:
Constant Field Values
Constructor Detail

VICTwitter

public VICTwitter(java.lang.String consumKey,
                  java.lang.String consumSecret)

VICTwitter

public VICTwitter(java.lang.String consumKey,
                  java.lang.String consumSecret,
                  twitter4j.http.AccessToken accessToken)
Method Detail

getTwitter4j

public twitter4j.Twitter getTwitter4j()

getConsumerKey

public java.lang.String getConsumerKey()

getConsumerSecret

public java.lang.String getConsumerSecret()

getOAuthRequestToken

public twitter4j.http.RequestToken getOAuthRequestToken()
                                                 throws java.lang.Exception
Get Twitter Request token

Returns:
RequestToken, which can be used for the Authentication phase of the OAuth protocol.
Throws:
java.lang.Exception

getAuthenticationURL

public java.lang.String getAuthenticationURL()
                                      throws java.lang.Exception
Get Twitter Authentication (OAuth protocol) URL.

Returns:
Authentication URL.
For example: https://twitter.com/oauth/authenticate?oauth_token=ykFhTqVrjq2EAf6Zn3alyexpmkViKzILzWpmiVcA4
Throws:
java.lang.Exception

getAuthenticationURL

public java.lang.String getAuthenticationURL(twitter4j.http.RequestToken requestToken)
                                      throws java.lang.Exception
Get Twitter Authentication (OAuth protocol) URL

Parameters:
requestToken - RequestToken, which used for the Authentication phase of the OAuth protocol.
Returns:
Authentication URL.
For example: https://twitter.com/oauth/authenticate?oauth_token=ykFhTqVrjq2EAf6Zn3alyexpmkViKzILzWpmiVcA4
Throws:
java.lang.Exception

getAccessToken

public twitter4j.http.AccessToken getAccessToken()
                                          throws java.lang.Exception
Returns an access token associated with this instance.

Returns:
Access token associated with this instance, or new token if no access token associated with current instance.
Throws:
java.lang.Exception

getAccessTokenDetails

public java.lang.String[] getAccessTokenDetails()
                                         throws java.lang.Exception
Returns an access token and password.

Returns:
String array of 2:
result[VICTwitter.TOKEN] - access token value
result[VICTwitter.TOKEN_SECRET] - access token secret value.
Throws:
java.lang.Exception

getAccessToken

public twitter4j.http.AccessToken getAccessToken(twitter4j.Twitter vTwitter)
                                          throws java.lang.Exception
Returns an access token associated with this instance. Can be used for web applications SSO with Twitter.

Parameters:
vTwitter - associated Twitter (twitter4j) session.
Returns:
Access token associated with this instance, or new token if no access token associated with current instance.
Throws:
java.lang.Exception

getAccessToken

public twitter4j.http.AccessToken getAccessToken(java.lang.String token,
                                                 java.lang.String tokenSecret)
                                          throws java.lang.Exception
Returns an access token associated with this instance.

Parameters:
token - access token
tokenSecret access token secret.
Returns:
Access token associated with token and tokenSecret.
Throws:
java.lang.Exception

loadTwiterUser

public twitter4j.User loadTwiterUser()
                              throws java.lang.Exception
Returns Twitter user representation if authentication was successful.

Returns:
Twitter user representation.
Throws:
java.lang.Exception

getTwiterUser

public twitter4j.User getTwiterUser()
                             throws java.lang.Exception
Returns Twitter user representation of already authentication session (see loadTwiterUser).

Returns:
Twitter user representation.
Throws:
java.lang.Exception

showUser

public twitter4j.User showUser(java.lang.String screenName)
                        throws java.lang.Exception
Returns given Twitter user (screenName) representation.

Parameters:
screenName - Twitter user screen name.
Returns:
Twitter user representation.
Throws:
java.lang.Exception

showUser

public twitter4j.User showUser(int userId)
                        throws java.lang.Exception
Returns given Twitter user (id) representation.

Parameters:
userId - Twitter user ID
Returns:
Twitter user representation.
Throws:
java.lang.Exception

shutdown

public void shutdown()
Release all recourse associated with this session.


getUserName

public java.lang.String getUserName(twitter4j.User u)
Get Twitter user name.

Parameters:
u - Twitter user representation.
Returns:
Twitter user name. If u not provided (null), the user name of authenticated user (see loadTwiterUser) will be returned.

getUserScreenName

public java.lang.String getUserScreenName(twitter4j.User u)
Get Twitter user screen name.

Parameters:
u - Twitter user representation.
Returns:
Twitter user screen name. If u not provided (null), the user screen name of authenticated user (see loadTwiterUser) will be returned.

getUserDescription

public java.lang.String getUserDescription(twitter4j.User u)
Get Twitter user description.

Parameters:
u - Twitter user representation.
Returns:
Twitter user description. If u not provided (null), the user description of authenticated user (see loadTwiterUser) will be returned.

getUserFollowers

public java.lang.String[] getUserFollowers(int limit)
                                    throws java.lang.Exception
Get Twitter user followers.

Parameters:
limit - maximum number of followers to be returned
Returns:
Array of twitter followers of authenticated user.
Throws:
java.lang.Exception

getUserFriends

public java.lang.String[] getUserFriends(int limit)
                                  throws java.lang.Exception
Get Twitter user friends.

Parameters:
limit - maximum number of friends to be returned
Returns:
Array of twitter friends of authenticated user.
Throws:
java.lang.Exception

getRateLimitStatus

public twitter4j.RateLimitStatus getRateLimitStatus()
                                             throws java.lang.Exception
Get Twitter user Rate Limit details.

Returns:
Rate Limit Status of currently authenticated twitter user.
Throws:
java.lang.Exception

getHourlyLimit

public int getHourlyLimit(twitter4j.RateLimitStatus rateLimitSts)
                   throws java.lang.Exception
Get Twitter user hourly API call limitations.

Parameters:
rateLimitSts - Rate Limit Status (see getRateLimitStatus).
Returns:
Hourly API call limit of currently authenticated twitter user.
Throws:
java.lang.Exception

getRemainingHits

public int getRemainingHits(twitter4j.RateLimitStatus rateLimitSts)
                     throws java.lang.Exception
Get Twitter user remaining API call limit.

Parameters:
rateLimitSts - Rate Limit Status (see getRateLimitStatus).
Returns:
Remaining API call limit of currently authenticated twitter user.
Throws:
java.lang.Exception

getSecondsUntilReset

public int getSecondsUntilReset(twitter4j.RateLimitStatus rateLimitSts)
                         throws java.lang.Exception
Time in seconds, left for reset hourly limit.

Parameters:
rateLimitSts - Rate Limit Status (see getRateLimitStatus).
Returns:
Seconds till next limit reset of currently authenticated twitter user.
Throws:
java.lang.Exception

sendDirectMessage

public void sendDirectMessage(java.lang.String screenName,
                              java.lang.String text)
                       throws java.lang.Exception
Send direct message to another twitter user.

Parameters:
screenName - recipient twitter user screen name
text message to be sent (max 140 chars).
Throws:
java.lang.Exception

updateStatus

public void updateStatus(java.lang.String text)
                  throws java.lang.Exception
Update status of authenticated Twitter user.

Parameters:
text - status (max 140 chars).
Throws:
java.lang.Exception

follow

public twitter4j.User follow(java.lang.String screenName)
                      throws java.lang.Exception
Follow another Twitter user.

Parameters:
screenName - followed twitter user screen name
Returns:
Followed Twitter user representation.
Throws:
java.lang.Exception