List of usage examples for twitter4j Status getId
long getId();
From source file:br.unisal.twitter.bean.TwitterBean.java
public void postingToTwitter() { try {// ww w. j a v a 2s .c o m TwitterFactory TwitterFactory = new TwitterFactory(); Twitter twitter = TwitterFactory.getSingleton(); String message = getTwitt(); Status status = twitter.updateStatus(message); /*String s = "status.toString() = " + status.toString() + "status.getInReplyToScreenName() = " + status.getInReplyToScreenName() + "status.getSource() = " + status.getSource() + "status.getText() = " + status.getText() + "status.getContributors() = " + Arrays.toString(status.getContributors()) + "status.getCreatedAt() = " + status.getCreatedAt() + "status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId() + "status.getGeoLocation() = " + status.getGeoLocation() + "status.getId() = " + status.getId() + "status.getInReplyToStatusId() = " + status.getInReplyToStatusId() + "status.getInReplyToUserId() = " + status.getInReplyToUserId() + "status.getPlace() = " + status.getPlace() + "status.getRetweetCount() = " + status.getRetweetCount() + "status.getRetweetedStatus() = " + status.getRetweetedStatus() + "status.getUser() = " + status.getUser() + "status.getAccessLevel() = " + status.getAccessLevel() + "status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()) + "status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()) + "status.getURLEntities() = " + Arrays.toString(status.getURLEntities()) + "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities());*/ String s = "status.getId() = " + status.getId() + "\nstatus.getUser() = " + status.getUser().getName() + " - " + status.getUser().getScreenName() + "\nstatus.getGeoLocation() = " + status.getGeoLocation() + "\nstatus.getText() = " + status.getText(); setTwittsResult(s); this.getUiMsg().setSubmittedValue(""); this.getUiResultMsg().setSubmittedValue(getTwittsResult()); } catch (TwitterException ex) { LOG.error("Erro no postingToTwitter() - " + ex.toString()); } }
From source file:cats.twitter.collect.Collect.java
@Override public boolean runCollect() { dateEnd = Calendar.getInstance(); dateEnd.add(Calendar.DAY_OF_YEAR, duree); cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);// www . j a v a2 s . c om cb.setOAuthConsumerKey(user.getConsumerKey()); System.out.println("CONSUMER KEY " + user.getConsumerKey()); cb.setOAuthConsumerSecret(user.getConsumerSecret()); System.out.printf("CONSUMER SECRET " + user.getConsumerSecret()); cb.setOAuthAccessToken(user.getToken()); System.out.printf("TOKEN" + user.getToken()); cb.setOAuthAccessTokenSecret(user.getTokenSecret()); System.out.printf("TOKEN SECRET " + user.getTokenSecret()); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); setStatus(State.WAITING_FOR_CONNECTION); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { if (!corpus.getState().equals(State.INPROGRESS)) { setStatus(State.INPROGRESS); } if (status.getCreatedAt().after(dateEnd.getTime())) { shutdown(); } else if (corpus.getLang() == null || corpus.getLang().equals(status.getLang())) { Tweet t = new Tweet(); t.setText(status.getText().replace("\r", "\n")); t.setAuthor(status.getUser().getId()); t.setId(status.getId()); t.setDate(status.getCreatedAt()); if (status.getGeoLocation() != null) t.setLocation(status.getGeoLocation().toString()); t.setName(status.getUser().getName()); t.setDescriptionAuthor(status.getUser().getDescription()); t.setLang(status.getLang()); t.setCorpus(corpus); if (tweetRepository != null) tweetRepository.save(t); } } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { System.out.println(sdn); } @Override public void onTrackLimitationNotice(int i) { corpus.setLimitationNotice(i); corpus = corpusRepository.save(corpus); } @Override public void onScrubGeo(long l, long l1) { System.out.println(l + "" + l1); } @Override public void onStallWarning(StallWarning sw) { System.out.println(sw); } @Override public void onException(Exception excptn) { corpus.setErrorMessage(excptn.getMessage()); setStatus(State.ERROR); excptn.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.filter(filter); return false; }
From source file:cc.twittertools.corpus.demo.ReadStatuses.java
License:Apache License
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input directory or file") .create(INPUT_OPTION));/*from ww w. j a v a 2 s .com*/ options.addOption(VERBOSE_OPTION, false, "print logging output every 10000 tweets"); options.addOption(DUMP_OPTION, false, "dump statuses"); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ReadStatuses.class.getName(), options); System.exit(-1); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream; // Figure out if we're reading from HTML SequenceFiles or JSON. File file = new File(cmdline.getOptionValue(INPUT_OPTION)); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } if (file.isDirectory()) { stream = new JsonStatusCorpusReader(file); } else { stream = new JsonStatusBlockReader(file); } int cnt = 0; Status status; while ((status = stream.next()) != null) { if (cmdline.hasOption(DUMP_OPTION)) { String text = status.getText(); if (text != null) { text = text.replaceAll("\\s+", " "); text = text.replaceAll("\0", ""); } out.println(String.format("%d\t%s\t%s\t%s", status.getId(), status.getUser().getScreenName(), status.getCreatedAt(), text)); } cnt++; if (cnt % 10000 == 0 && cmdline.hasOption(VERBOSE_OPTION)) { LOG.info(cnt + " statuses read"); } } stream.close(); LOG.info(String.format("Total of %s statuses read.", cnt)); }
From source file:cc.twittertools.index.ExtractTweetidsFromCollection.java
License:Apache License
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); CommandLine cmdline = null;/* w w w. j a v a 2 s. co m*/ CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractTweetidsFromCollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { System.out.println(status.getId() + "\t" + status.getUser().getScreenName()); } }
From source file:cc.twittertools.util.ExtractSubcollection.java
License:Apache License
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); options.addOption(/*from w w w . j a va2 s . co m*/ OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION)); options.addOption( OptionBuilder.withArgName("file").hasArg().withDescription("output JSON").create(OUTPUT_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file to store missing tweeids").create(MISSING_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION) || !cmdline.hasOption(OUTPUT_OPTION) || !cmdline.hasOption(MISSING_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractSubcollection.class.getName(), options); System.exit(-1); } String outputFile = cmdline.getOptionValue(OUTPUT_OPTION); String missingFile = cmdline.getOptionValue(MISSING_OPTION); String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); LongOpenHashSet tweetids = new LongOpenHashSet(); File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION)); if (!tweetidsFile.exists()) { System.err.println("Error: " + tweetidsFile + " does not exist!"); System.exit(-1); } LOG.info("Reading tweetids from " + tweetidsFile); FileInputStream fin = new FileInputStream(tweetidsFile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String s; while ((s = br.readLine()) != null) { tweetids.add(Long.parseLong(s)); } br.close(); fin.close(); LOG.info("Read " + tweetids.size() + " tweetids."); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } // Store tweet ids we've already seen to dedup. LongOpenHashSet seen = new LongOpenHashSet(); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { if (tweetids.contains(status.getId()) && !seen.contains(status.getId())) { out.write(TwitterObjectFactory.getRawJSON(status) + "\n"); seen.add(status.getId()); } } stream.close(); out.close(); LOG.info("Extracted " + seen.size() + " tweetids."); LOG.info("Storing missing tweetids..."); out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(missingFile), "UTF-8")); LongIterator iter = tweetids.iterator(); while (iter.hasNext()) { long t = iter.nextLong(); if (!seen.contains(t)) { out.write(t + "\n"); } } out.close(); LOG.info("Done!"); }
From source file:cc.twittertools.util.VerifySubcollection.java
License:Apache License
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); options.addOption(//from ww w . j av a2s . c o m OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractSubcollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); LongOpenHashSet tweetids = new LongOpenHashSet(); File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION)); if (!tweetidsFile.exists()) { System.err.println("Error: " + tweetidsFile + " does not exist!"); System.exit(-1); } LOG.info("Reading tweetids from " + tweetidsFile); FileInputStream fin = new FileInputStream(tweetidsFile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String s; while ((s = br.readLine()) != null) { tweetids.add(Long.parseLong(s)); } br.close(); fin.close(); LOG.info("Read " + tweetids.size() + " tweetids."); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } LongOpenHashSet seen = new LongOpenHashSet(); TreeMap<Long, String> tweets = Maps.newTreeMap(); PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream = new JsonStatusCorpusReader(file); Status status; int cnt = 0; while ((status = stream.next()) != null) { if (!tweetids.contains(status.getId())) { LOG.error("tweetid " + status.getId() + " doesn't belong in collection"); continue; } if (seen.contains(status.getId())) { LOG.error("tweetid " + status.getId() + " already seen!"); continue; } tweets.put(status.getId(), TwitterObjectFactory.getRawJSON(status)); seen.add(status.getId()); cnt++; } LOG.info("total of " + cnt + " tweets in subcollection."); for (Map.Entry<Long, String> entry : tweets.entrySet()) { out.println(entry.getValue()); } stream.close(); out.close(); }
From source file:ch.schrimpf.core.TwitterCrawler.java
License:Open Source License
/** * Performs a single crawl step according to the previous initialized query * until the specified limit is reached. Received tweets are stored in the * *.csv specified in the easyTwitterCrawler.properties file. * <p/>/*from w w w . ja v a 2 s . c o m*/ * TODO make selecting values flexible * * @param limit to stop on */ public void crwal(int limit) { LOG.info("receiving tweets..."); int i = 0; while (i < limit && running) { try { QueryResult res = twitter.search(query); if (res.getMaxId() > last) { for (Status status : res.getTweets()) { String[] line = { String.valueOf(status.getId()), String.valueOf(status.getCreatedAt()), status.getText(), String.valueOf(status.getUser()), String.valueOf(status.getPlace()), status.getLang() }; csv.writeResult(Arrays.asList(line)); i++; } last = res.getMaxId(); } else { break; } } catch (TwitterException e) { LOG.warning("could not process tweets"); } } tweets += i; LOG.info(i + " tweets received in this crawl"); LOG.info("totally " + tweets + " received"); }
From source file:co.cask.cdap.template.etl.realtime.source.TwitterSource.java
License:Apache License
private StructuredRecord convertTweet(Status tweet) { StructuredRecord.Builder recordBuilder = StructuredRecord.builder(this.schema); recordBuilder.set(ID, tweet.getId()); recordBuilder.set(MSG, tweet.getText()); recordBuilder.set(LANG, tweet.getLang()); Date tweetDate = tweet.getCreatedAt(); if (tweetDate != null) { recordBuilder.set(TIME, tweetDate.getTime()); }// ww w.j a v a2s.c om recordBuilder.set(FAVC, tweet.getFavoriteCount()); recordBuilder.set(RTC, tweet.getRetweetCount()); recordBuilder.set(SRC, tweet.getSource()); if (tweet.getGeoLocation() != null) { recordBuilder.set(GLAT, tweet.getGeoLocation().getLatitude()); recordBuilder.set(GLNG, tweet.getGeoLocation().getLongitude()); } recordBuilder.set(ISRT, tweet.isRetweet()); return recordBuilder.build(); }
From source file:co.cask.hydrator.plugin.realtime.source.TwitterSource.java
License:Apache License
private StructuredRecord convertTweet(Status tweet) { StructuredRecord.Builder recordBuilder = StructuredRecord.builder(SCHEMA); recordBuilder.set(ID, tweet.getId()); recordBuilder.set(MSG, tweet.getText()); recordBuilder.set(LANG, tweet.getLang()); Date tweetDate = tweet.getCreatedAt(); if (tweetDate != null) { recordBuilder.set(TIME, tweetDate.getTime()); }/*from w w w . j ava 2 s . co m*/ recordBuilder.set(FAVC, tweet.getFavoriteCount()); recordBuilder.set(RTC, tweet.getRetweetCount()); recordBuilder.set(SRC, tweet.getSource()); if (tweet.getGeoLocation() != null) { recordBuilder.set(GLAT, tweet.getGeoLocation().getLatitude()); recordBuilder.set(GLNG, tweet.getGeoLocation().getLongitude()); } recordBuilder.set(ISRT, tweet.isRetweet()); return recordBuilder.build(); }
From source file:cojoytuerto.CojoYTuertoFrame.java
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked // TODO add your handling code here: if (evt.getClickCount() == 2) { Status ms = mensajes.get(jTable1.getSelectedRow()); DefaultTableModel tm = (DefaultTableModel) jTable1.getModel(); if (jTable1.getColumnName(jTable1.getSelectedColumn()).equals("FV")) { //FV// www . j a v a2s . c om System.out.println("FV: " + ms.getText()); try { twitter.createFavorite(ms.getId()); } catch (TwitterException ex) { Logger.getLogger(CojoYTuertoFrame.class.getName()).log(Level.SEVERE, null, ex); } tm.setValueAt("FV", jTable1.getSelectedRow(), jTable1.getSelectedColumn()); } else if (jTable1.getColumnName(jTable1.getSelectedColumn()).equals("RT")) { //RT if (!ms.isRetweetedByMe()) { try { twitter.retweetStatus(ms.getId()); System.out.println("RT: " + mensajes.get(jTable1.getSelectedRow()).getText()); } catch (TwitterException ex) { Logger.getLogger(CojoYTuertoFrame.class.getName()).log(Level.SEVERE, null, ex); } } tm.setValueAt("RT", jTable1.getSelectedRow(), jTable1.getSelectedColumn()); } } }