Exemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 public AccessToken getOAuthAccessToken(final String screenName, final String password)
     throws TwitterException {
   try {
     final String url = conf.getOAuthAccessTokenURL();
     if (0 == url.indexOf("http://")) {
       // SSL is required
       // @see https://dev.twitter.com/docs/oauth/xauth
       // url = "https://" + url.substring(7);
     }
     final String sign_url = conf.getSigningOAuthAccessTokenURL();
     if (0 == sign_url.indexOf("http://")) {
       // SSL is required
       // @see https://dev.twitter.com/docs/oauth/xauth
       // sign_url = "https://" + sign_url.substring(7);
     }
     oauthToken =
         new AccessToken(
             http.post(
                 url,
                 sign_url,
                 new HttpParameter[] {
                   new HttpParameter("x_auth_username", screenName),
                   new HttpParameter("x_auth_password", password),
                   new HttpParameter("x_auth_mode", "client_auth")
                 },
                 this));
     return (AccessToken) oauthToken;
   } catch (final TwitterException te) {
     throw new TwitterException(
         "The screen name / password combination seems to be invalid.", te, te.getStatusCode());
   }
 }
Exemplo n.º 2
0
 /** {@inheritDoc} */
 public AccessToken getOAuthAccessToken() throws TwitterException {
   ensureTokenIsAvailable();
   if (oauthToken instanceof AccessToken) {
     return (AccessToken) oauthToken;
   }
   oauthToken = new AccessToken(http.post(conf.getOAuthAccessTokenURL(), this));
   return (AccessToken) oauthToken;
 }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 public AccessToken getOAuthAccessToken(String oauthVerifier) throws TwitterException {
   ensureTokenIsAvailable();
   oauthToken =
       new AccessToken(
           http.post(
               conf.getOAuthAccessTokenURL(),
               new HttpParameter[] {new HttpParameter("oauth_verifier", oauthVerifier)},
               this));
   return (AccessToken) oauthToken;
 }
Exemplo n.º 4
0
 /**
  * Retrieves an access token associated with the supplied screen name and password using xAuth.
  * <br>
  * In order to get access acquire AccessToken using xAuth, you must apply by sending an email to
  * [email protected] — 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.<br>
  * 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.
  *
  * @param screenName the screen name
  * @param password the password
  * @return access token associated with the supplied request token.
  * @throws TwitterException when Twitter service or network is unavailable, or the user has not
  *     authorized
  * @see <a href="http://dev.twitter.com/pages/oauth_faq">OAuth FAQ | dev.twitter.com - How long
  *     does an access token last?</a>
  * @see <a
  *     href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-oauth-access_token-for-xAuth">Twitter
  *     REST API Method: oauth access_token for xAuth</a>
  * @since Twitter 2.1.1
  */
 public AccessToken getOAuthAccessToken(String screenName, String password)
     throws TwitterException {
   try {
     oauthToken =
         new AccessToken(
             http.post(
                 conf.getOAuthAccessTokenURL(),
                 new HttpParameter[] {
                   new HttpParameter("x_auth_username", screenName),
                   new HttpParameter("x_auth_password", password),
                   new HttpParameter("x_auth_mode", "client_auth")
                 },
                 this));
     return (AccessToken) oauthToken;
   } catch (TwitterException te) {
     throw new TwitterException(
         "The screen name / password combination seems to be invalid.", te, te.getStatusCode());
   }
 }
Exemplo n.º 5
0
 /** {@inheritDoc} */
 @Override
 public AccessToken getOAuthAccessToken(final String oauthVerifier) throws TwitterException {
   ensureTokenIsAvailable();
   final String url = conf.getOAuthAccessTokenURL();
   if (0 == url.indexOf("http://")) {
     // SSL is required
     // @see https://dev.twitter.com/docs/oauth/xauth
     // url = "https://" + url.substring(7);
   }
   final String sign_url = conf.getSigningOAuthAccessTokenURL();
   if (0 == sign_url.indexOf("http://")) {
     // SSL is required
     // @see https://dev.twitter.com/docs/oauth/xauth
     // sign_url = "https://" + sign_url.substring(7);
   }
   oauthToken =
       new AccessToken(
           http.post(
               url,
               sign_url,
               new HttpParameter[] {new HttpParameter("oauth_verifier", oauthVerifier)},
               this));
   return (AccessToken) oauthToken;
 }