List of usage examples for twitter4j TwitterFactory getInstance
public Twitter getInstance(Authorization auth)
From source file:com.springsource.greenhouse.connect.providers.Twitter4JServiceProvider.java
License:Apache License
protected Twitter createServiceOperations(OAuthToken accessToken) { TwitterFactory twitterFactory = new TwitterFactory(); AccessToken oauthToken = new AccessToken(accessToken.getValue(), accessToken.getSecret()); Configuration configuration = new PropertyConfiguration(new Properties()); Authorization authorization = new OAuthAuthorization(configuration, getApiKey(), getSecret(), oauthToken); return accessToken != null ? twitterFactory.getInstance(authorization) : twitterFactory.getInstance(); }
From source file:com.thesmartweb.swebrank.TwitterAnalysis.java
License:Apache License
/** * Method to get tweets regarding a string * @param query_string the string to search for * @param config_path the directory with the twitter api key * @return the tweets in a string/*from w w w. j a v a 2s . c o m*/ */ public String perform(String query_string, String config_path) { try { List<String> twitterkeys = GetKeys(config_path); //configuration builder in order to set the keys of twitter ConfigurationBuilder cb = new ConfigurationBuilder(); String consumerkey = twitterkeys.get(0); String consumersecret = twitterkeys.get(1); String accesstoken = twitterkeys.get(2); String accesstokensecret = twitterkeys.get(3); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerkey).setOAuthConsumerSecret(consumersecret) .setOAuthAccessToken(accesstoken).setOAuthAccessTokenSecret(accesstokensecret); TwitterFactory tf = new TwitterFactory(cb.build()); AccessToken acc = new AccessToken(accesstoken, accesstokensecret); Twitter twitter = tf.getInstance(acc); //query the twitter Query query = new Query(query_string); int rpp = 100; query.count(rpp); query.setQuery(query_string); //----------get the tweets------------ QueryResult result = twitter.search(query); List<Status> tweets = result.getTweets(); RateLimitStatus rls = result.getRateLimitStatus(); String tweet_txt = ""; for (Status tweet : tweets) { tweet_txt = tweet_txt + " " + tweet.getText(); } DataManipulation txtpro = new DataManipulation(); Stopwords st = new Stopwords(); tweet_txt = txtpro.removeChars(tweet_txt); tweet_txt = st.stop(tweet_txt); tweet_txt = txtpro.removeChars(tweet_txt); return tweet_txt; } catch (TwitterException ex) { String tweet_txt = ""; Logger.getLogger(TwitterAnalysis.class.getName()).log(Level.SEVERE, null, ex); return tweet_txt = "fail"; } }
From source file:org.taverna.server.master.notification.TwitterDispatcher.java
private Twitter getTwitter(String key, String secret) throws Exception { if (key.isEmpty() || secret.isEmpty()) throw new NoCredentialsException(); Properties p = getConfig();/* www .j ava 2 s .c o m*/ p.setProperty(OAUTH_CONSUMER_KEY, key); p.setProperty(OAUTH_CONSUMER_SECRET, secret); Configuration config = new PropertyConfiguration(p); TwitterFactory factory = new TwitterFactory(config); Twitter t = factory.getInstance(AuthorizationFactory.getInstance(config)); // Verify that we can connect! t.getOAuthAccessToken(); return t; }
From source file:twitterplugin.TwitterSender.java
License:Open Source License
public void send(final Window parentWindow, final Program program, final TwitterSettings settings) { TwitterDialog dialog = new TwitterDialog(parentWindow, program, settings.getFormat()); dialog.setLocationRelativeTo(parentWindow); dialog.setVisible(true);/*from w ww.ja va 2s.c o m*/ if (dialog.wasOkPressed()) { if (settings.getAccessToken() == null) { final TwitterLoginDialog login = new TwitterLoginDialog(parentWindow, settings); if (!(login.askLogin() == JOptionPane.OK_OPTION)) { return; } } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(settings.getConsumerKey()) .setOAuthConsumerSecret(settings.getConsumerSecret()); TwitterFactory factory = new TwitterFactory(cb.build()); AccessToken accessToken = settings.getAccessToken(); Twitter twitter = factory.getInstance(accessToken); try { twitter.updateStatus(dialog.getMessage()); DontShowAgainMessageBox.dontShowAgainMessageBox(TwitterPlugin.getInstance(), "tweetSent", parentWindow, mLocalizer.msg("tweetSend", "The tweet was sent.")); } catch (TwitterException e) { e.printStackTrace(); ErrorHandler.handle(mLocalizer.msg("error", "Could not send tweet..."), e); } } }
From source file:uk.co.flax.ukmp.twitter.PartyListHandler.java
License:Apache License
public void refreshLists() { Map<String, Set<Long>> memberIds = new HashMap<>(); Authorization auth = AuthorizationFactory.getInstance(twitterConfig); TwitterFactory tf = new TwitterFactory(twitterConfig); Twitter twitter = tf.getInstance(auth); for (PartyConfiguration pc : parties.values()) { Set<Long> ids = readPartyIds(twitter, pc.getTwitterScreenName(), pc.getTwitterListSlug(), pc.getDisplayName());// ww w.ja v a 2s . c o m if (!ids.isEmpty()) { memberIds.put(pc.getDisplayName(), ids); } } synchronized (partyMemberIds) { for (String party : memberIds.keySet()) { if (!partyMemberIds.containsKey(party) || Sets.symmetricDifference(memberIds.get(party), partyMemberIds.get(party)).size() > 0) { hasChanged = true; partyMemberIds.put(party, memberIds.get(party)); LOGGER.debug("Updated list for {} with {} ids", party, memberIds.get(party).size()); } } } if (hasChanged) { updateTime = new Date(); memberParties.clear(); } }