private AccessToken getAccessToken(Session session, String user) throws InterruptedException { AccessToken accessToken = null; try { LoadTwitterConfigAction ltc = new LoadTwitterConfigAction(); ltc.setSession(session); ltc.setTwitterUser(user); ltc.execute(); TwitterConfig tc = ltc.getTwitterConfig(); if (tc != null) { accessToken = new AccessToken(tc.getToken(), tc.getTokenSecret()); } else { System.err.println( "[GERCOM] ATENCAO - Nao há token e tokensecret para o usuário registrado - ATENCAO"); } } catch (Exception ex) { System.err.println(ex.getMessage()); Thread.sleep(60000); return null; } return accessToken; }
private boolean saveAccessToken(Session session, String token, String tokenSecret) { AddTwitterConfig addTwitterConfig = new AddTwitterConfig(); addTwitterConfig.setSession(session); TwitterConfig tc = new TwitterConfig(); tc.setConsumerKey(TwitterApp.CONSUMER_KEY); tc.setConsumerSecret(TwitterApp.CONSUMER_SECRET); tc.setTwitterUser(TwitterApp.TWITTER_USER); tc.setToken(token); tc.setTokenSecret(tokenSecret); tc.setValid(true); tc.setDateTwitterConfig(new Date(System.currentTimeMillis())); addTwitterConfig.setTwitterConfig(tc); addTwitterConfig.execute(); return true; }