Esempio n. 1
0
 public boolean authorize() {
   if (isAuthenticated) {
     return true;
   }
   String token = "";
   try {
     System.out.println("Trying to authenticate");
     xauth = new XAuth(username, password);
     token = xauth.xAuthWebRequest(false, OAUTH_ACCESS_TOKEN_URL, null, null);
     System.out.println("ACCESS TOKEN: " + token);
     if (token.indexOf("oauth_token_secret") > 0) {
       // Success
       String oauthToken = HttpUtil.parseParameter(token, "oauth_token");
       String oauthTokenSecret = HttpUtil.parseParameter(token, "oauth_token_secret");
       xauth.setTokenAndSecret(oauthToken, oauthTokenSecret);
       isAuthenticated = true;
       authErrStatus = null;
       return true;
     } else {
       // Failure
       authErrStatus =
           new Status("Twitter", "Couldn't find OAuth token from response: " + token, null, "");
       isAuthenticated = false;
       return false;
     }
   } catch (Exception ex) {
     authErrStatus =
         new Status("Twitter", "Couldn't authenticate. Exception: " + ex.getMessage(), null, "");
     isAuthenticated = false;
     return false;
   }
 }