List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:edu.csupomona.nlp.tool.crawler.Twitter.java
/** * Construct Twitter for crawling with Stream API * @throws IOException//from w w w . java 2 s .c om */ public Twitter() throws IOException { // init default parameters lang_ = "en"; includeRetweet_ = false; // init default restriction sizeLimit_ = 3000; hourLimit_ = 24; // 24 hours // read and construct property Properties key = new Properties(); key.load(getClass().getResourceAsStream("/etc/twitter.properties")); // set authentication key&token ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(key.getProperty("ConsumerKey")) .setOAuthConsumerSecret(key.getProperty("ConsumerSecret")) .setOAuthAccessToken(key.getProperty("AccessToken")) .setOAuthAccessTokenSecret(key.getProperty("AccessTokenSecret")); // create twitter stream ts_ = new TwitterStreamFactory(cb.build()).getInstance(); // add listener ts_.addListener(new StatusListener() { @Override public void onStatus(Status status) { // only record tweet matches requirement if (isRetweetMatch(status) && !isIdRedundant(status)) { String text = status.getText(); Long id = status.getId(); text = text.replaceAll("\\n", ""); // to the same line tweet_.add(id.toString() + ":" + text); idSet_.add(id); } System.out.println( "[" + idSet_.size() + "/" + sizeLimit_ + "]" + status.getId() + ": " + status.getText()); // when limit is reached if (isLimitReached()) { try { // write tweet to file finishup(); } catch (IOException ex) { Logger.getLogger(Twitter.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void onTrackLimitationNotice(int i) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void onScrubGeo(long l, long l1) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void onStallWarning(StallWarning sw) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void onException(Exception excptn) { excptn.printStackTrace(); // anything wrong, just save everything we have and stop try { finishup(); } catch (IOException ex) { Logger.getLogger(Twitter.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:edu.lander.twitter.TwitStreaming.java
public void prepareDownloadTweets(int newType, long limit) { setType(newType);//w ww . j av a2s . c o m if (getType() == TIME_LIMIT) { timeTweetDownloadLimit = limit; } else if (getType() == NUMBER_LIMIT) { nTweetDownloadLimit = limit; } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(getConsumerKey()).setOAuthConsumerSecret(getConsumerSecret()) .setOAuthAccessToken(getAccessToken()).setOAuthAccessTokenSecret(getAccessTokenSecret()) .setJSONStoreEnabled(true); connectMongoDB(); listener = new TweetDownloadListener(this); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); twitterStream.addListener(listener); }
From source file:edu.mum.cs.wap.TwitterUtil.java
private static Twitter getTwitter() { if (twitter == null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("ZhsCVnhHjs54ZLCxgE82n6GEa") .setOAuthConsumerSecret("FixRe4imh376SRWcxgoF14GdyaQjW7tLHE13mxcgNXNiObwSnr") .setOAuthAccessToken("935445715-EcVDaqqw7QQgcviXSOWWDT5ZCT8LkHbBNP1Pzd1W") .setOAuthAccessTokenSecret("PJIEzaRZB21tZP01CAaZEoEaVEcVvIRK6jMOlDyqc0peL"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();//from w w w. j a v a2 s .c om } return twitter; }
From source file:edu.proyectofinal.integradorrs.services.tweets.impl.TweetsServiceImpl.java
@Override public Collection<Status> getAllTweets(String email) { TwitterCredentials tc = TwitterCredentials.getInstance(); ConfigurationBuilder cb = tc.GetCredentials(email); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/*from w ww .ja va 2s . com*/ List<Status> statuses = null; try { statuses = twitter.getHomeTimeline(); } catch (TwitterException ex) { Logger.getLogger(TweetsServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } Collection<Status> result = (Collection<Status>) statuses; return result; }
From source file:edu.proyectofinal.integradorrs.services.tweets.impl.TweetsServiceImpl.java
@Override public Collection<Status> getUserTimeline(String user, String email) { TwitterCredentials tc = TwitterCredentials.getInstance(); ConfigurationBuilder cb = tc.GetCredentials(email); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/*w w w .java 2s. c o m*/ List<Status> statuses = null; Paging paging = new Paging(1, 30); try { statuses = twitter.getUserTimeline(user, paging); } catch (TwitterException ex) { Logger.getLogger(TweetsServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } Collection<Status> result = (Collection<Status>) statuses; return result; }
From source file:edu.smc.mediacommons.panels.TwitterPanel.java
License:Open Source License
public TwitterPanel() { setLayout(null);//from www . j av a 2 s. c o m jButton = Utils.createButton("Login", 210, 100, 100, 20, null); add(jButton); passwordField = new JPasswordField(); passwordField.setBounds(110, 100, 100, 20); add(passwordField); message = Utils.createLabel("Sign-in to Authenticate API calls", 80, 70, 300, 20, Resources.VERDANA_14_BOLD); add(message); // You can use your own credentials, and choose to encrypt them or not /* String tempEncrypted = null; try { InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("YOUR_PATH"); InputStreamReader streamReader = new InputStreamReader(inputStream, "UTF-8"); BufferedReader reader = new BufferedReader(streamReader); tempEncrypted = reader.readLine(); } catch (IOException e) { }*/ final String encrypted = null; jButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); textEncryptor.setPassword(passwordField.getText()); String[] decrypted = textEncryptor.decrypt(encrypted).split("\\$"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(decrypted[0]).setOAuthConsumerSecret(decrypted[1]) .setOAuthAccessToken(decrypted[2]).setOAuthAccessTokenSecret(decrypted[3]); TwitterFactory tf = new TwitterFactory(cb.build()); twitterModule = new TwitterModule(tf.getInstance()); } catch (Exception ex) { JOptionPane.showMessageDialog(getParent(), "The input password was not correct."); return; } JOptionPane.showMessageDialog(getParent(), "Authentication successful."); restructurePanel(); } }); }
From source file:edu.uci.ics.asterix.external.util.TwitterUtil.java
License:Apache License
public static Twitter getTwitterService(Map<String, String> configuration) { ConfigurationBuilder cb = getAuthConfiguration(configuration); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();//w ww .j av a 2 s . co m return twitter; }
From source file:edu.uci.ics.asterix.external.util.TwitterUtil.java
License:Apache License
public static TwitterStream getTwitterStream(Map<String, String> configuration) { ConfigurationBuilder cb = getAuthConfiguration(configuration); TwitterStreamFactory factory = new TwitterStreamFactory(cb.build()); return factory.getInstance(); }
From source file:ens.demo.twitter.TwittEmergencyMessage.java
@Override public void run() { try {/*from w w w . j av a 2s. c o m*/ if (toCustomer.getToken() == null || toCustomer.getToken().isEmpty()) { return; } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Properties properties = new Properties(); properties.load(classLoader.getResourceAsStream("twitter4j.properties")); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(properties.getProperty("twitter4j.oauth.consumerKey")) .setOAuthConsumerSecret(properties.getProperty("twitter4j.oauth.consumerSecret")) .setOAuthAccessToken(toCustomer.getToken()) .setOAuthAccessTokenSecret(toCustomer.getTokenSecret()); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); StatusUpdate update = new StatusUpdate(message); Status status = twitter.updateStatus(update); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (TwitterException ex) { Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:entities.TwitterFeed.java
public void initTimeline() { timelineFrame = new JFrame("@SIM_IST Timeline"); timelineFrame.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); timelineBack = new JButton("Back"); timelineBack.addActionListener(this); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5;//from w w w . j av a2 s.c o m c.gridx = 1; c.gridy = 1; c.gridwidth = 1; timelineFrame.add(timelineBack, c); timelineTweets = new JTextArea(); Font font = new Font("Gotham Narrow", Font.BOLD, 12); timelineTweets.setFont(font); timelineTweets.setEditable(false); timelineScrollPane = new JScrollPane(timelineTweets); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.ipady = 200; c.gridx = 0; c.gridy = 0; c.gridwidth = 3; timelineFrame.add(timelineScrollPane, c); KeyReader keys = new KeyReader(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(keys.getConsumerKey()) .setOAuthConsumerSecret(keys.getConsumerSecret()).setOAuthAccessToken(keys.getAccessToken()) .setOAuthAccessTokenSecret(keys.getAccessTokenSecret()); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { System.out.println("timeline retreval worked"); List<Status> statuses = twitter.getHomeTimeline(); for (Status status : statuses) { timelineTweets .append("@" + status.getUser().getScreenName() + " : " + status.getText() + "\n" + "\n"); timelineTweets.setLineWrap(true); timelineTweets.setWrapStyleWord(true); timelineTweets.setCaretPosition(0); System.out.println("@" + status.getUser().getName() + " : " + status.getText()); } } catch (TwitterException te) { System.out.print("timeline retreval failed"); te.printStackTrace(); } timelineFrame.pack(); timelineFrame.setSize(600, 300); timelineFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); timelineFrame.setLocationRelativeTo(null); timelineFrame.setVisible(true); }