List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey
public ConfigurationBuilder setOAuthConsumerKey(String oAuthConsumerKey)
From source file:uk.co.flax.ukmp.twitter.AbstractTwitterClient.java
License:Apache License
protected Configuration buildConfiguration() throws IOException { Map<String, String> authMap = readAuthConfiguration(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthAccessToken(authMap.get(ACCESS_TOKEN)); cb.setOAuthAccessTokenSecret(authMap.get(ACCESS_SECRET)); cb.setOAuthConsumerKey(authMap.get(CONSUMER_KEY)); cb.setOAuthConsumerSecret(authMap.get(CONSUMER_SECRET)); return cb.build(); }
From source file:ws.project.languagebasedlexiconanalisys.TwitterStreamAnalizer.java
void parseStream() throws IOException { //Inizializza file JSON FileWriter file = new FileWriter("data.json"); JSONObject obj = new JSONObject(); final JSONArray data = new JSONArray(); obj.put("data", data); file.write(obj.toJSONString());//from ww w. j av a 2 s. c o m file.flush(); file.close(); SimpleDateFormat currentDate = new SimpleDateFormat(); currentDate.applyPattern("dd-MM-yyyy"); final String currentDateStr = currentDate.format(new Date()); ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg.setOAuthAccessToken("3065669171-9Hp3VZbz7f0BCsvWWFfgywgqimSIp1AlT98745S"); cfg.setOAuthAccessTokenSecret("AUmg0AdhHzMXisnP1WV7Wnsw5amWFQPyIojI5aBG5qV4A"); cfg.setOAuthConsumerKey("arieQRhL2WwgRFfXFLAJp5Hkw"); cfg.setOAuthConsumerSecret("NvmWqgN1UKKPUWoh9d9Z2PuQobOah8IR5faqX2WjDGBL053sWE"); StatusListener listener; listener = new StatusListener() { @Override public void onStatus(Status status) { SimpleDateFormat tweetDate = new SimpleDateFormat(); tweetDate.applyPattern("dd-MM-yyyy"); String tweetDateStr = tweetDate.format(status.getCreatedAt()); try { indexer.openWriter(currentDateStr); } catch (IOException ex) { Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex); } //CHIUDO se cambio giorno ma non ho raggiunto l'1% if (!tweetDateStr.equals(currentDateStr)) { try { indexer.closeWriter(); } catch (IOException ex) { Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex); } writeOnJson(currentDateStr); System.out.println("Giorno successivo, completato senza aver raggiunto 1%"); System.exit(0); } tot_count++; if (status.getLang().equals("it")) { it_count++; try { indexer.addTweet(id, status.getText()); } catch (IOException ex) { Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex); } } try { indexer.closeWriter(); } catch (IOException ex) { Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onStallWarning(StallWarning sw) { } @Override public void onException(Exception excptn) { TwitterException exc = (TwitterException) excptn; if (exc.exceededRateLimitation()) { try { indexer.closeWriter(); } catch (IOException ex) { Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex); } writeOnJson(currentDateStr); System.out.println("1% raccolto, dati raccolti. Amen"); } } }; TwitterStream twitterStream = new TwitterStreamFactory(cfg.build()).getInstance(); twitterStream.addListener(listener); indexer.addIndex(currentDateStr); indexer.openWriter(currentDateStr); twitterStream.sample(); }