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:main.TwitterController.java

License:Open Source License

public void getOthersTimeline(String uname) throws TwitterException {
    User user = twitter.getUserDetail(uname);
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(printUser(user));

    List<Status> statusList = twitter.getUserTimeline(uname);
    int counter = 0;

    Iterator<Status> iterator = statusList.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + s.getText());
        if (counter % 10 == 0) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;/*from  ww w  .  j  a v  a 2 s. com*/
            try {
                str = in.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q'))
                return;
        }
    }
}

From source file:main.TwitterController.java

License:Open Source License

public void getTimeline() throws TwitterException {
    List<Status> statusList = null;
    int counter = 0;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    statusList = twitter.getFriendsTimeline();

    Iterator<Status> iterator = statusList.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + printUser(s.getUser()) + ": "
                + s.getText());
        if (counter % 10 == 0) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;/*w  ww  .ja  va 2 s.c  o m*/
            try {
                str = in.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q'))
                return;
        }
    }
}

From source file:MainScreen.Display.java

/**
 * Displays the 5 most recent tweets from the established twitter account
 * link onto their respective jLabels (in chronological order).
 *
 * @throws TwitterException/*  www .ja v  a 2s  .  c  o m*/
 */
public void displayTweets() throws TwitterException {
    System.out.println("Showing home timeline.");

    int currentYear = Calendar.getInstance().get(Calendar.YEAR);

    try {
        setTwitPic();
    } catch (IOException ex) {
        Logger.getLogger(Display.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (Status status : statuses) {
        if (status.getText().contains(Integer.toString(currentYear))) {
            returnNumber(statuses.indexOf(status))
                    .setText("Picture tweet! Check the twitter for announcements!");
        } else {
            returnNumber(statuses.indexOf(status)).setText("<html>@<b>" + status.getUser().getScreenName()
                    + "</b> - <i>" + status.getUser().getName() + "</i>: <br>" + status.getText() + "</html>");
        }

    }

}

From source file:mapper.TweetDataMapper.java

/**
* Transform a {@link Status} into an {@link Tweet}.
*
* @param status Object to be transformed.
* @return {@link Tweet}.// www .  j  av  a 2  s  . c o  m
*/
@Override
public Tweet transform(Status status) {
    if (status == null) {
        throw new IllegalArgumentException("Cannot transform a null value");
    }
    Tweet tweet = new Tweet();
    tweet.setCreateAt(status.getCreatedAt());
    tweet.setLang(status.getLang());
    if (status.getGeoLocation() != null) {
        tweet.setLat(status.getGeoLocation().getLatitude());
        tweet.setLon(status.getGeoLocation().getLongitude());
    }
    tweet.setReTweetCount(status.getRetweetCount());
    tweet.setText(status.getText());
    return tweet;

}

From source file:mashup.MashTweetManager.java

public static ArrayList<String> getTweets(String topic) throws IOException {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthAccessToken(Common.AccessToken)
            .setOAuthAccessTokenSecret(Common.AccessTokenSecret).setOAuthConsumerKey(Common.ConsumerKey)
            .setOAuthConsumerSecret(Common.ConsumerSecret);

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();//from w  w w  . j  av  a  2 s. c om

    //Twitter twitter = new TwitterFactory().getInstance();

    //  twitter.setOAuthAccessToken(null);

    ArrayList<String> tweetList = new ArrayList<>();

    try {
        Query query = new Query(topic.toLowerCase().trim());

        query.setCount(100);
        query.setLocale("en");
        query.setLang("en");

        QueryResult result = null;

        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();

            for (Status tweet : tweets) {
                String data = tweet.getText().replaceAll("[^\\p{L}\\p{Z}]", "");

                HinghlishStopWords.removeStopWords(data.trim());
                // Remove Special... Characters 
                // Remove stop words 
                tweetList.add(tweet.getText().replaceAll("[^\\p{L}\\p{Z}]", ""));

            }

        } while ((query = result.nextQuery()) != null);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
    }
    return tweetList;
}

From source file:me.chester.myretweetedtweets.User.java

License:Apache License

public List<String> getMyRetweetedTweets() throws TwitterException {
    if (token == null || tokenSecret == null) {
        throw new IllegalStateException("Token and secret have not been set up and confirmed yet");
    }//from  www  . j  av a 2  s .co m
    AccessToken accessToken = new AccessToken(token, tokenSecret);
    twitter.setOAuthAccessToken(accessToken);
    List<String> tweets = new ArrayList<String>(MAX_RETWEETED_TWEETS);
    for (Status status : twitter.getRetweetsOfMe()) {
        tweets.add(status.getText());
    }
    return tweets;
}

From source file:me.timothy.twittertoreddit.TwitterToReddit.java

License:Open Source License

public void postTweet(Status status) {
    if (status.getUser().getId() != twitterId)
        return;//from  w w  w.  ja v a2 s .c o m
    String text = status.getText();
    // Find the first hyperlink
    System.out.println(status.getUser().getName() + " - " + text);
    Matcher matcher = URL_PATTERN.matcher(text);
    if (matcher.find()) {
        String firstLink = matcher.group();
        System.out.println("  Link: " + firstLink);

        firstLink = LinkUnshortener.unshorten(restClient, firstLink);
        System.out.println("  Unshortened: " + firstLink);
        String realText = text.substring(0, matcher.start()).trim();

        try {
            redditUser.submitLink(realText, firstLink, subreddit);
        } catch (IOException | ParseException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        System.out.println("  Failed to find link");
    }
}

From source file:miproyectolunadepluton.MiProyectoLunaDePluton.java

/**
 * @param args the command line arguments
 *//*from w  w w .ja  v  a 2 s .  c  om*/
public static void main(String[] args) throws TwitterException {
    /* ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)      
      .setOAuthConsumerKey("BNmJ2oaezMC2qciIgkpC33kYq")
    .setOAuthConsumerSecret("1b0xCDy2Qh5nFWeuJjdF1MDcjpVJTh4LSpjTfUKeabacirUOn4")
    .setOAuthAccessToken("708080587068858368-FxuwrHLsox7xVSQRbwjDV14vOpSxNyN")
    .setOAuthAccessTokenSecret("c4gBOfVZL7MwyhI7jVPVrGupnNJAiZAJ2cDE9qp48OVl1");*/
    TwitterFactory tf = new TwitterFactory();
    Twitter mitwitter = tf.getInstance();
    for (int i = 0; i < 11150; i++) {
        Status mistatus = mitwitter.updateStatus("Me la bufa");
        System.out.println(mistatus.getText());

    }
}

From source file:mitwitter.MiTwitter.java

/**
 * @param args the command line arguments
 */// w  w  w  .j ava  2s .c o  m
public static void main(String[] args) throws TwitterException {
    // TODO code application logic here

    //camobios

    Twitter twitter = new TwitterFactory().getInstance();

    //CODIGO CAMBIAR ESTADO
    Status miStatus = twitter.updateStatus("Tercer ejemplo");//cambia el estado de twitter
    System.out.println(miStatus.getText());

    //CODIGO TIMELINE
    List<Status> statuses = twitter.getHomeTimeline();
    System.out.println("Showing home timeline.");//aparecen los ultimos twitts
    for (Status status : statuses) {
        System.out.println(status.getUser().getName() + ":" + status.getText());
    }

    //CODIGO BUSCAR TAGS
    Query query = new Query("Chelsea"); //Dentro del String va el tag que quieres buscar
    QueryResult result = twitter.search(query);
    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
    }

}

From source file:moderation.Moderate.java

public List getTwitterpost() {

    List posts = new ArrayList();
    try {// w  w  w.j  a va2  s. c  o m
        List savedpost = getSavedList(album_id);
        String tagname = this.hash;
        Twitter twitter = setting.TwitterToken.twitterObject();
        Query query = new Query(tagname);
        query.setCount(50);
        QueryResult result;
        result = twitter.search(query);
        List<Status> tweets = result.getTweets();
        for (Status tweet : tweets) {
            System.out.println("\n\n\n" + tweet);
            PostModel post = new PostModel();
            post.setAlbum_id(this.album_id);
            if (savedpost.contains(tweet.getId()))
                post.setStatus("old");
            else
                post.setStatus("new");
            post.setPost_id("" + tweet.getId());
            post.setSender_name(URLEncoder.encode(tweet.getUser().getScreenName(), "UTF-8"));
            post.setCaption_text(URLEncoder.encode(tweet.getText(), "UTF-8"));
            post.setSender_pic(tweet.getUser().getProfileImageURL());
            post.setSender_id("" + tweet.getUser().getId());

            for (MediaEntity mediaEntity : tweet.getMediaEntities()) {
                post.setImage_standard(mediaEntity.getMediaURL());
                post.setImage_low(mediaEntity.getMediaURL());
            }
            post.setPost_time(tweet.getCreatedAt().toString());
            post.setType("twitter_post");
            post.setLink(null);
            post.setParam("post_id=" + post.getPost_id() + "&album_id=" + post.getAlbum_id() + "&type="
                    + post.getType() + "&post_time=" + post.getPost_time() + "&link=" + post.getLink()
                    + "&pic_low=" + post.getImage_low() + "&pic_standard=" + post.getImage_standard()
                    + "&post_message=" + post.getCaption_text() + "&sender_name=" + post.getSender_name()
                    + "&sender_id=" + post.getSender_id() + "&sender_pic=" + post.getSender_pic());

            posts.add(post);

        }
        this.twitternext = result.nextQuery();

    } catch (Exception e) {
        System.err.println("Exception occure in getTwitter " + e);
    }

    return posts;
}