Example usage for twitter4j Status getText

List of usage examples for twitter4j Status getText

Introduction

In this page you can find the example usage for twitter4j Status getText.

Prototype

String getText();

Source Link

Document

Returns the text of the status

Usage

From source file:br.ufba.dcc.tagcloud.util.TwitterProvider.java

public void getTweets(Twitter twitter, String user, int max) throws TwitterException {
    List<Status> tweets = new ArrayList<Status>();
    for (int i = 1; i < 20; i++) {
        tweets.addAll(twitter.getUserTimeline(user, new Paging(i, max)));
    }/*w w w  .  ja v a  2 s.  c  om*/
    for (Status tweet : tweets) {
        this.texts.add(tweet.getText());
    }
}

From source file:br.unisal.twitter.bean.TwitterBean.java

public void postingToTwitter() {
    try {//w ww.ja  va 2 s .co 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:br.unisal.twitter.bean.TwitterBean.java

public void consultarTweets() {
    TwitterFactory TwitterFactory = new TwitterFactory();
    Twitter twitter = TwitterFactory.getSingleton();
    List<Status> tweets = new ArrayList<>();
    Query query = new Query(getTwittQuery());
    try {//from   w w w  .  j av  a  2s.  c o  m
        QueryResult result = twitter.search(query);
        tweets.addAll(result.getTweets());
        StringBuilder builder = new StringBuilder();
        double lon = 0;
        double lat = 0;
        for (Status s : tweets) {
            if ((s.getGeoLocation() != null)) {
                lon = s.getGeoLocation().getLongitude();
                lat = s.getGeoLocation().getLatitude();
            }
            Tweet t = new Tweet(s.getUser().getName(), s.getUser().getLocation(), s.getText(), s.getCreatedAt(),
                    lat, lon);
            dao.insert(t);
            builder.append(t.toString());
        }
        this.getUiResultQuery().setSubmittedValue(builder.toString());
    } catch (TwitterException te) {
        System.out.println("Failed to search tweets: " + te.getMessage());
    }
}

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);//from w  w w . ja  v a  2s  . 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));/* ww w  . j  a  va2  s.  co m*/
    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:cd.examentwitter.Metodos.java

/**
 * Metodo para visualizar todo el timeLine del usuario logueado
 *//*from w  w w.j a  v  a 2 s .c  om*/
public void timeLine() {

    try {
        List<Status> statuses = twitter.getHomeTimeline();

        System.out.println("Mostrando timeline");
        for (Status status : statuses) {
            System.out.println(status.getUser().getName() + ": " + status.getText());
        }
    } catch (TwitterException ex) {
        Logger.getLogger(Metodos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cd.examentwitter.Metodos.java

/**
 * Metodo para buscar una determinada secuencia caracteres por todo Twitter
 *///  w ww  .  j a  v a  2 s .c om
public void search() {

    try {
        String search = JOptionPane.showInputDialog("Qu secuencia de caracteres desea buscar?");
        QueryResult result = twitter.search(new Query(search));

        for (Status status : result.getTweets()) {
            System.out.println("@" + status.getUser().getScreenName() + ": " + status.getText());
        }
    } catch (TwitterException ex) {
        Logger.getLogger(Metodos.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:cd.examentwitter.Metodos.java

/**
 * Metodo para publicar un tuit publico en el timeline del usuario logueado
 *///  w w  w .j  a  v  a 2 s .  c  om
public void tweet() {

    try {
        Status status = twitter.updateStatus(Metodos.tuit());
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
    } catch (TwitterException ex) {
        Logger.getLogger(Metodos.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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/>/*w  ww  .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:chillerbot.ChillTweet.java

public List<String> getNewLinks(HashMap<Color, String> colorsToLinks) throws TwitterException {
    ArrayList<String> links = new ArrayList();
    for (Status each : getStatusesFromUser("@everycolorbot")) {
        String[] statusText = (each.getText().replace("0x", "#").split(" "));
        if (!colorsToLinks.values().contains(statusText[1])) {
            links.add(statusText[0] + " " + statusText[1]);
        }//from   w  w w.  j a  v a  2  s  .c  o m
    }
    return links;
}