List of usage examples for twitter4j.auth AccessToken AccessToken
public AccessToken(String token, String tokenSecret)
From source file:com.tuncaysenturk.jira.plugins.jtp.twitter.JiraTwitterStreamImpl.java
public void startListener() { if (!licenseValidator.isValid()) { logger.error(JTPConstants.LOG_PRE + "License problem, see configuration page"); ExceptionMessagesUtil.addLicenseExceptionMessage(); } else if (null != listener) { // it should not come here // first it has to be stopped logger.warn(JTPConstants.LOG_PRE + "This is another attempt to stream twitter account that has already been streaming by another thread." + "It has to be stopped before."); } else {/* w w w.j a va2s .c om*/ twitterStream = new TwitterStreamFactory().getInstance(); try { listener = new JiraTwitterUserStreamListener(); listener.setJiraTwitterStream(twitterStream); listener.setJiraTwitterIssueService(issueService); listener.setLicenseValidator(licenseValidator); listener.setTweetIssueRelService(tweetIssueRelService); if (null == twitterStream.getConfiguration().getOAuthConsumerKey() || null == twitterStream.getConfiguration().getOAuthConsumerSecret()) twitterStream.setOAuthConsumer(propSet.getString("consumerKey"), propSet.getString("consumerSecret")); try { AccessToken accessToken = new AccessToken(propSet.getString("accessToken"), propSet.getString("accessTokenSecret")); twitterStream.setOAuthAccessToken(accessToken); } catch (IllegalStateException e) { logger.error(JTPConstants.LOG_PRE + "Exception while obtaining access tokens", e); ExceptionMessagesUtil.addExceptionMessage("Exception while obtaining access tokens : ", e); } twitterStream.addListener(listener); twitterStream.user(); listener.setScreenName(twitterStream.getScreenName()); logger.info(JTPConstants.LOG_PRE + "Successfully streaming twitter account"); } catch (Exception e) { logger.error(JTPConstants.LOG_PRE + "Error while streaming", e); ExceptionMessagesUtil.addExceptionMessage("Error while streaming : ", e); } } }
From source file:com.twitstreet.twitter.AdsListenerMgrImpl.java
License:Open Source License
@Override public void start() { TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); Announcer announcer = announcerMgr.randomAnnouncerData(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream// w w w.j a v a 2 s.c o m .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { HashtagEntity[] hashtagEntities = status.getHashtagEntities(); String screenName = status.getUser().getScreenName(); User user = status.getUser(); if (user != null && (System.currentTimeMillis() - lastMessage > TEN_MIN)) { lastMessage = System.currentTimeMillis(); int action = (int) (ACTION_TYPES * Math.random()); switch (action) { case REGULAR_TWEET: LocalizationUtil lutil = LocalizationUtil.getInstance(); int sentenceSize = Integer .parseInt(lutil.get("announcer.sentence.size", LocalizationUtil.DEFAULT_LANGUAGE)); int random = (int) (Math.random() * sentenceSize); String rndMessage = lutil.get("announcer.sentence." + random, LocalizationUtil.DEFAULT_LANGUAGE); announcerMgr.announceFromRandomAnnouncer(rndMessage); break; case RETWEEET: announcerMgr.retweet(status.getId()); break; case FAVOURITE: announcerMgr.favourite(status.getId()); break; default: String message = constructAdsMessage(screenName, hashtagEntities, status.getUser().getLang()); announcerMgr.reply(message, status.getId()); break; } } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.AnnouncerMgrImpl.java
License:Open Source License
public void loadAnnouncers() { Connection connection = null; PreparedStatement ps = null;//from w w w . j a v a2 s . c o m ResultSet rs = null; try { connection = dbMgr.getConnection(); ps = connection.prepareStatement(LOAD_ANNOUNCER); rs = ps.executeQuery(); while (rs.next()) { Announcer announcer = new Announcer(); announcer.getDataFromResultSet(rs); announcerDataList.add(announcer); if (TWITSTREET_GAME.equals(announcer.getName())) { twitstreetGame = new TwitterFactory().getInstance(); twitstreetGame.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitstreetGame.setOAuthAccessToken( new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); } else { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitter.setOAuthAccessToken( new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); announcerList.add(twitter); } } logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString()); } catch (SQLException ex) { logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex); } finally { dbMgr.closeResources(connection, ps, rs); } }
From source file:com.twitstreet.twitter.FollowBackMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream/* www .j a v a 2 s. c om*/ .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { if (System.currentTimeMillis() - lastFollow > FOLLOW_INTERVAL) { twitter4j.User user = status.getUser(); announcerMgr.follow(user.getId()); lastFollow = System.currentTimeMillis(); } // if(System.currentTimeMillis() - lastFollowDiabloBird > FOLLOW_INTERVAL/6){ // twitter4j.User user = status.getUser(); // announcerMgr.followForDiabloBird(user.getId()); // lastFollowDiabloBird = System.currentTimeMillis(); // } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.TwitstreetAnnouncerImpl.java
License:Open Source License
@Override public boolean mention(Stock stock, String message) { if (addStockIntoAnnouncement(stock.getId())) { twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(configMgr.getAnnouncerConsumerKey(), configMgr.getAnnouncerConsumerSecret()); twitter.setOAuthAccessToken(// www . j a v a 2s . co m new AccessToken(configMgr.getAnnouncerAccessToken(), configMgr.getAnnouncerAccessSecret())); try { twitter.updateStatus("@" + stock.getName() + " " + message); } catch (TwitterException e) { logger.error("sendMessage:" + stock.getName() + " " + message); } return true; } return false; }
From source file:com.twitstreet.twitter.TwitterProxyImpl.java
License:Open Source License
@Inject public TwitterProxyImpl(ConfigMgr configMgr, @Assisted("oauthToken") String oauthToken, @Assisted("oauthTokenSecret") String oauthTokenSecret) { this.configMgr = configMgr; Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(configMgr.getConsumerKey(), configMgr.getConsumerSecret()); accessToken = new AccessToken(oauthToken, oauthTokenSecret); oToken = oauthToken;/* www . j a v a 2 s.c om*/ oSecret = oauthTokenSecret; twitter.setOAuthAccessToken(accessToken); this.setTwitter(twitter); //top woiedMap.put("Worldwide", 1); //1 woiedMap.put("Argentina", 23424747); woiedMap.put("Australia", 23424748); woiedMap.put("Brazil", 23424768); woiedMap.put("Canada", 23424775); woiedMap.put("Chile", 23424782); woiedMap.put("Colombia", 23424787); woiedMap.put("Dominican Republic", 23424800); woiedMap.put("Ecuador", 23424801); woiedMap.put("France", 23424819); woiedMap.put("Germany", 23424829); woiedMap.put("Guatemala", 23424834); woiedMap.put("India", 23424848); //2 woiedMap.put("Indonesia", 23424846); woiedMap.put("Ireland", 23424803); woiedMap.put("Italy", 23424853); woiedMap.put("Japan", 23424856); woiedMap.put("Malaysia", 23424901); woiedMap.put("Mexico", 23424900); woiedMap.put("Netherlands", 23424909); woiedMap.put("New Zeland", 23424916); woiedMap.put("Nigeria", 23424908); woiedMap.put("Pakistan", 23424922); woiedMap.put("Peru", 23424919); woiedMap.put("Philippines", 23424934); //3 woiedMap.put("Russia", 23424936); woiedMap.put("Singapore", 23424948); woiedMap.put("South Africa", 23424942); woiedMap.put("Spain", 23424950); woiedMap.put("Sweden", 23424954); woiedMap.put("Turkey", 23424969); woiedMap.put("United Arab Emirates", 23424738); woiedMap.put("United Kingdom", 23424975); woiedMap.put("United States", 23424977); woiedMap.put("Venezuela", 23424982); }
From source file:com.twitstreet.twitter.Welcome2ListenerMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream/* w ww . j a v a 2 s . com*/ .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { UserMentionEntity[] userMentionEntities = status.getUserMentionEntities(); for (UserMentionEntity userMentionEntity : userMentionEntities) { idSet.add(userMentionEntity.getId()); if (idSet.size() >= TwitterProxyImpl.IDS_SIZE) { List<User> userList = twitterProxy.getTwUsers(new ArrayList<Long>(idSet)); if (userList != null) { for (User user : userList) { if (user.getFollowersCount() > MIN_FOLLOWER_COUNT_FOR_TREND) { Stock stock = new Stock(user); stockMgr.saveStock(stock); stockMgr.saveTrend(stock.getId()); } } } idSet.clear(); } } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.vuze.client.plugins.twitter.TwitterPlugin.java
License:Open Source License
public void initialize(PluginInterface _plugin_interface) { plugin_interface = _plugin_interface; String ac_str = plugin_interface.getPluginconfig().getPluginStringParameter("twitter.access.token", ""); String acs_str = plugin_interface.getPluginconfig().getPluginStringParameter("twitter.access.token.secret", "");/*from www .j a va 2 s . c o m*/ if (ac_str.length() > 0 && acs_str.length() > 0) { access_token = new AccessToken(ac_str, acs_str); } ta_tweets = plugin_interface.getTorrentManager().getPluginAttribute("tweets"); final LocaleUtilities loc_utils = plugin_interface.getUtilities().getLocaleUtilities(); log = plugin_interface.getLogger().getChannel("Twitter"); UIManager ui_manager = plugin_interface.getUIManager(); config_model = ui_manager.createBasicPluginConfigModel("plugins", "twitter.name"); enable = config_model.addBooleanParameter2(CONFIG_ENABLE, "twitter.enable", CONFIG_ENABLE_DEFAULT); LabelParameter tweet_info = config_model.addLabelParameter2("twitter.tweet.info"); tweet_text = config_model.addStringParameter2(CONFIG_TWEET_ADDED, CONFIG_TWEET_ADDED, loc_utils.getLocalisedMessageText(CONFIG_TWEET_ADDED_DEFAULT)); ParameterGroup tweet_group = config_model.createGroup("twitter.tweet.group", new Parameter[] { tweet_info, tweet_text }); // twitter_user = config_model.addStringParameter2( CONFIG_TWITTER_USER, "twitter.user", "" ); // twitter_password = config_model.addPasswordParameter2( CONFIG_TWITTER_PASSWORD, "twitter.password", PasswordParameter.ET_PLAIN, new byte[0] ); LabelParameter oauth_info = config_model.addLabelParameter2("twitter.oauth.info"); final ActionParameter oauth_setup = config_model.addActionParameter2("twitter.oauth.start.label", "twitter.oauth.start.button"); final RequestToken[] request_token = { null }; final StringParameter oauth_pin = config_model.addStringParameter2("twitter.oauth.pin", "twitter.oauth.pin", ""); oauth_pin.setValue(""); final ActionParameter oauth_done = config_model.addActionParameter2("twitter.oauth.done.label", "twitter.oauth.done.button"); oauth_setup.addConfigParameterListener(new ConfigParameterListener() { public void configParameterChanged(ConfigParameter param) { oauth_setup.setEnabled(false); plugin_interface.getUtilities().createThread("Twitter Setup", new Runnable() { public void run() { Twitter twitter = new TwitterFactory().getInstance(); try { RequestToken requestToken = twitter.getOAuthRequestToken(); request_token[0] = requestToken; oauth_done.setEnabled(true); log.log("OAuth URL: " + requestToken.getAuthorizationURL()); plugin_interface.getUIManager().openURL(new URL(requestToken.getAuthorizationURL())); Thread.sleep(5000); } catch (Throwable e) { log.log("OAuth setup failed", e); plugin_interface.getUIManager().showMessageBox("twitter.oauth.error.title", "twitter.oauth.error.details", UIManagerEvent.MT_OK); } finally { oauth_setup.setEnabled(true); } } }); } }); oauth_done.addConfigParameterListener(new ConfigParameterListener() { public void configParameterChanged(ConfigParameter param) { plugin_interface.getUtilities().createThread("Twitter Setup", new Runnable() { public void run() { try { Twitter twitter = new TwitterFactory().getInstance(); AccessToken at = twitter.getOAuthAccessToken(request_token[0], oauth_pin.getValue()); access_token = at; String token = at.getToken(); String token_secret = at.getTokenSecret(); plugin_interface.getPluginconfig().setPluginParameter("twitter.access.token", token); plugin_interface.getPluginconfig().setPluginParameter("twitter.access.token.secret", token_secret); plugin_interface.getPluginconfig().save(); log.log("OAuth setup successful - token saved"); plugin_interface.getUIManager().showMessageBox("twitter.oauth.ok.title", "twitter.oauth.ok.details", UIManagerEvent.MT_OK); } catch (Throwable e) { log.log("OAuth setup failed", e); plugin_interface.getUIManager().showMessageBox("twitter.oauth.error.title", "twitter.oauth.error.details", UIManagerEvent.MT_OK); } } }); } }); oauth_done.setEnabled(false); ParameterGroup auth_group = config_model.createGroup("twitter.oauth.group", new Parameter[] { oauth_info, oauth_setup, oauth_pin, oauth_done }); ActionParameter action = config_model.addActionParameter2("twitter.tweet_test", "twitter.send"); action.addConfigParameterListener(new ConfigParameterListener() { public void configParameterChanged(ConfigParameter param) { plugin_interface.getUtilities().createThread("Twitter Test", new Runnable() { public void run() { Map<String, String> params = new HashMap<String, String>(); params.put("%t", "<test_torrent_name>"); params.put("%m", "<magnet_uri>"); TwitterResult result = sendTweet(params); if (result.isOK()) { plugin_interface.getUIManager().showMessageBox("twitter.testok.title", "twitter.testok.details", UIManagerEvent.MT_OK); } else { plugin_interface.getUIManager() .showMessageBox("twitter.testfail.title", "!" + loc_utils.getLocalisedMessageText("twitter.testfail.details", new String[] { result.getError() }) + "!", UIManagerEvent.MT_OK); } } }); } }); view_model = ui_manager.createBasicPluginViewModel(loc_utils.getLocalisedMessageText("twitter.name")); view_model.getActivity().setVisible(false); view_model.getProgress().setVisible(false); log.addListener(new LoggerChannelListener() { public void messageLogged(int type, String content) { view_model.getLogArea().appendText(content + "\n"); } public void messageLogged(String str, Throwable error) { view_model.getLogArea().appendText(str + "\n"); view_model.getLogArea().appendText(error.toString() + "\n"); } }); view_model.getStatus().setText(enable.getValue() ? "Enabled" : "Disabled"); enable.addListener(new ParameterListener() { public void parameterChanged(Parameter p) { view_model.getStatus().setText(enable.getValue() ? "Enabled" : "Disabled"); checkEnabled(); } }); enable.addEnabledOnSelection(tweet_info); enable.addEnabledOnSelection(tweet_text); enable.addEnabledOnSelection(oauth_info); enable.addEnabledOnSelection(oauth_setup); enable.addEnabledOnSelection(oauth_pin); enable.addEnabledOnSelection(oauth_done); enable.addEnabledOnSelection(action); plugin_interface.getUIManager().addUIListener(new UIManagerListener() { public void UIAttached(UIInstance instance) { if (instance instanceof UISWTInstance) { checkEnabled(); } } public void UIDetached(UIInstance instance) { } }); timer = plugin_interface.getUtilities().createTimer("refresher"); timer_event = timer.addPeriodicEvent(60 * 1000, this); plugin_interface.getDownloadManager().addListener(this); }
From source file:com.yattatech.dbtc.dao.SystemPreferences.java
License:Open Source License
public AccessToken getTwitterAccessToken() { Debug.d(TAG, "getTwitterAccessToken"); // Don't log nothing about twitter tokens for security reason // someone could use adb to take log messages and find out // easily current token final String token = mPrefs.getString(TWITTER_TOKEN, null); final String tokenSecret = mPrefs.getString(TWITTER_TOKEN_SECRET, null); return new AccessToken(token, tokenSecret); }
From source file:com.zisal.twit.crawl.core.Example.java
public static void main(String[] args) { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(ApplicationConstant.TwitterKey.CUSTOMER_KEY, ApplicationConstant.TwitterKey.CUSTOMER_SECRET); twitter.setOAuthAccessToken(//from w w w .ja v a 2s .com new AccessToken(ApplicationConstant.TwitterKey.TOKEN, ApplicationConstant.TwitterKey.TOKEN_SECRET)); /*try{ ResponseList<Status> responseList = twitter.getUserTimeline(new Paging(1, 5)); for(Status s: responseList){ System.out.println("Response List ".concat(s.getText())); } }catch(Exception e){ e.printStackTrace(); } long cursor = -1; IDs ids = null; System.out.println("Listing followers's ids."); do { try { ids = twitter.getFollowersIDs(ApplicationConstant.Twitter.SCREEN_NAME, cursor); for (long id : ids.getIDs()) { System.out.println(id); User user = twitter.showUser(id); System.out.println(user.getName()); } } catch (TwitterException e) { e.printStackTrace(); } } while ((cursor = ids != null ? ids.getNextCursor() : 0) != 0);*/ long cursor = -1; PagableResponseList<User> pagableFollowings = null; List<User> listFriends = new ArrayList<>(); do { try { pagableFollowings = twitter.getFriendsList(18211861, cursor); for (User user : pagableFollowings) { listFriends.add(user); logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "friend #1st level " + user.getName()); /*PagableResponseList<User> _2ndLevelPageableFollowings = twitter.getFriendsList(user.getId(), cursor); for(User _2ndLevelFriend : _2ndLevelPageableFollowings){ logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "added friend #2nd level "+ _2ndLevelFriend.getName()); listFriends.add(_2ndLevelFriend); }*/ } } catch (TwitterException e) { e.printStackTrace(); } } while ((cursor = pagableFollowings.getNextCursor()) != 0); logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "friend total : " + listFriends.size()); for (User user : listFriends) { logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "friend : " + user.getName()); } /* cursor = -1; PagableResponseList<User> pagableFollowers = null; List<User> listFollowers = new ArrayList<>(); do { try { pagableFollowers = twitter.getFollowersList(twitter.getId(), cursor); for (User user : pagableFollowers) { listFollowers.add(user); // ArrayList<User> System.out.println(user.getName()); } } catch (TwitterException e) { e.printStackTrace(); } } while ((cursor = pagableFollowers.getNextCursor()) != 0); */ }