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:com.mycompany.dovetune.SearchTwitter.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   www .ja va2  s .c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, TwitterException {

    //            HttpSession session = request.getSession(false);

    //            if(session != null){

    Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");

    if (twitter != null) {
        String soundcloudUrl = request.getParameter("soundcloudUrl");
        String songName = request.getParameter("songName");
        out.println(twitter.toString());

        int i = songName.indexOf("- ");
        String song = songName.substring(i + 2);
        try {
            Query query = new Query("(#" + song + ") OR ( " + songName + ") OR (#DoveTune)");

            QueryResult result = twitter.search(query);

            List<Status> tweets = result.getTweets();
            //                String list = "<ulid='tweetList'>";
            String list = "";
            for (Status tweet : tweets) {
                list += "<li><img class='profileImg' src='" + tweet.getUser().getProfileImageURL()
                        + "' title='Profile Image' alt='Profile Image'><strong>" + tweet.getUser().getName()
                        + " @" + tweet.getUser().getScreenName() + "</strong> - " + tweet.getText() + "</li>";
            }

            list = list.replace("#" + song, "<strong class='hashtags'>#" + song + "</strong>");
            list = list.replace("#DoveTune", "<strong class='hashtags'>#DoveTune</strong>");
            list = list.replace("#SoundCloud", "<strong class='hashtags'>#SoundCloud</strong>");
            String songL = song;
            songL = songL.toLowerCase();
            list = list.replace("#" + songL, "<strong class='hashtags'>#" + songL + "</strong>");
            if (list.equals("")) {
                list = "<li>There are no tweets to display. Tweet your own!</li>";
            }

            request.setAttribute("soundcloudUrl", soundcloudUrl);
            request.setAttribute("songName", songName);
            request.setAttribute("song", songName);
            request.setAttribute("list", list);

        } catch (TwitterException te) {
            te.printStackTrace();
            out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
        }
    } else {
        String list = "<ul><li>In order to view tweets, please sign in to <a href=\"SignIn\" title=\"Sign in to Twitter\"><strong class=\"notSignedIn\">Twitter</strong></a></li></ul>";
        request.setAttribute("list", list);
    }

    request.getRequestDispatcher("details.jsp").forward(request, response);

}

From source file:com.mycompany.omnomtweets.Search.java

public static boolean writeToStdErr(Status tweet) {
    //System.out.println("Writing " + tweets.size() + " tweets");
    boolean success = true;
    if (tweet != null) {
        String tweetText;/*from w  w  w .ja  va 2  s  .  co  m*/
        String idOfRetweetee = "";
        if (tweet.getRetweetedStatus() != null) {
            tweetText = "RT " + tweet.getRetweetedStatus().getText();
            idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName();
            //System.out.println("retweeted" + tweetText);
        } else {
            tweetText = tweet.getText();
        }
        String urlText = "";
        if (tweet.getURLEntities().length > 0) {
            for (URLEntity url : tweet.getURLEntities()) {
                if (url.getExpandedURL() != null) {
                    urlText += url.getExpandedURL() + " ";
                    tweetText = tweetText.replace(url.getURL(), url.getExpandedURL());
                    //System.out.println("Expanded URL " + url.getExpandedURL());
                } else {
                    urlText += url.getURL() + " ";
                    //System.out.println("URL " + url.getURL());
                }
            }
        }
        if (tweet.getMediaEntities().length > 0) {
            for (MediaEntity media : tweet.getMediaEntities()) {
                if (media.getExpandedURL() != null) {
                    urlText += media.getExpandedURL() + " ";
                    tweetText = tweetText.replace(media.getMediaURL(), media.getExpandedURL());
                    //System.out.println("Expanded URL " + media.getExpandedURL());
                } else {
                    urlText += media.getMediaURL() + " ";
                    //System.out.println("URL " + media.getMediaURL());
                }
            }
        }
        String encodedText = tweetText.replaceAll("\"", "\"\"");
        encodedText = encodedText.replaceAll("\\s", " ");
        String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + ","
                + tweet.getId() + "," + candidate.name + "," + sdf.format(tweet.getCreatedAt()) + ","
                + idOfRetweetee + "\n";
        System.err.print(writeMe);
        //writeTweets.write(writeMe);
    }
    return success;
}

From source file:com.mycompany.omnomtweets.Search.java

/**
 * Method to write the tweets to file, base 64 encoded tweet text.
 * @param tweets the tweets to be written
 * @param filename the file to write the tweets into
 * @return true unless something bad happens
 *///from  ww  w.  ja  v a  2 s  .  c  om
public static boolean writeTweetsToFile(List<Status> tweets, String filename) {
    //System.out.println("Writing " + tweets.size() + " tweets");
    boolean success = true;
    try {
        FileWriter addTweets = new FileWriter(new File(filename), true);
        if (tweets != null && tweets.size() > 0) {
            for (Status tweet : tweets) {
                String tweetText;
                String idOfRetweetee = "";
                if (tweet.getRetweetedStatus() != null) {
                    tweetText = "RT " + tweet.getRetweetedStatus().getText();
                    idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName();
                    //System.out.println("retweeted" + tweetText);
                } else {
                    tweetText = tweet.getText();
                }
                String urlText = "";
                if (tweet.getURLEntities().length > 0) {
                    for (URLEntity url : tweet.getURLEntities()) {
                        if (url.getExpandedURL() != null) {
                            urlText += url.getExpandedURL() + " ";
                            tweetText = tweetText.replace(url.getURL(), url.getExpandedURL());
                            //System.out.println("Expanded URL " + url.getExpandedURL());
                        } else {
                            urlText += url.getURL() + " ";
                            //System.out.println("URL " + url.getURL());    
                        }
                    }
                }
                if (tweet.getMediaEntities().length > 0) {
                    for (MediaEntity media : tweet.getMediaEntities()) {
                        if (media.getExpandedURL() != null) {
                            urlText += media.getExpandedURL() + " ";
                            tweetText = tweetText.replace(media.getMediaURL(), media.getExpandedURL());
                            //System.out.println("Expanded URL " + media.getExpandedURL());
                        } else {
                            urlText += media.getMediaURL() + " ";
                            //System.out.println("URL " + media.getMediaURL());    
                        }
                    }
                }
                String encodedText = tweetText.replaceAll("\"", "\"\"");
                encodedText = encodedText.replaceAll("\n", " ");
                String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + ","
                        + tweet.getId() + "," + candidate.name + "," + tweet.getCreatedAt() + ","
                        + idOfRetweetee + "\n";
                //System.out.println(writeMe);
                addTweets.write(writeMe);
            }
        }
        addTweets.close();
    } catch (IOException ex) {
        //System.out.println("Something broke lol");
        success = false;
    }
    return success;
}

From source file:com.mycompany.omnomtweets.TweetsAboutCandidates.java

/**
 * Method to write the tweets to file, base 64 encoded tweet text.
 * @param tweets the tweets to be written
 * @param filename the file to write the tweets into
 * @return true unless something bad happens
 *//*from   w w  w  .  jav  a 2 s . c  o  m*/
public boolean writeTweetsToFile(List<Status> tweets, String filename) {
    //System.out.println("Writing " + tweets.size() + " tweets");
    boolean success = true;
    try {
        FileWriter addTweets = new FileWriter(new File(filename), true);
        if (tweets != null && tweets.size() > 0) {
            for (Status tweet : tweets) {
                String tweetText;
                String idOfRetweetee = "";
                if (tweet.getRetweetedStatus() != null) {
                    tweetText = "RT " + tweet.getRetweetedStatus().getText();
                    idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName();
                    //System.out.println("retweeted" + tweetText);
                } else {
                    tweetText = tweet.getText();
                }
                String urlText = "";
                if (tweet.getURLEntities().length > 0) {
                    for (URLEntity url : tweet.getURLEntities()) {
                        if (url.getExpandedURL() != null) {
                            urlText += url.getExpandedURL() + " ";
                            //System.out.println("Expanded URL " + url.getExpandedURL());
                        } else {
                            urlText += url.getURL() + " ";
                            //System.out.println("URL " + url.getURL());    
                        }
                    }
                }
                if (tweet.getMediaEntities().length > 0) {
                    for (MediaEntity media : tweet.getMediaEntities()) {
                        if (media.getExpandedURL() != null) {
                            urlText += media.getExpandedURL() + " ";
                            //System.out.println("Expanded URL " + media.getExpandedURL());
                        } else {
                            urlText += media.getMediaURL() + " ";
                            //System.out.println("URL " + media.getMediaURL());    
                        }
                    }
                }
                String encodedText = tweet.getText().replaceAll("\"", "\"\"");
                String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + ","
                        + tweet.getId() + "," + candidate.name + "," + tweet.getCreatedAt() + ","
                        + idOfRetweetee + "\n";
                //System.out.println(writeMe);
                addTweets.write(writeMe);
            }
        }
        addTweets.close();
    } catch (IOException ex) {
        System.out.println("Something broke lol");
        success = false;
    }
    return success;
}

From source file:com.mycompany.twitterapp.TwitterApp.java

public void getTimeline() {
    Set<String> keySet = listOfPeople.keySet();
    for (String key : keySet) {
        System.out.println("Debug Person - " + key);
        try {/*  w w  w  . ja va2 s.  co  m*/
            List<Status> statuses = null;
            for (int i = 1; i < 16; i++) {
                statuses = twitter.getUserTimeline(key, new Paging(i));
                System.out.println("Debug - filling statuses = " + i + " - Size: " + statuses.size());

                if (statuses.size() < 1 || statuses == null) {
                    System.out.println("List Empty.");
                    break;
                }
                //System.out.println("Showing @" + statuses.get(0).getUser().getScreenName() + "'s home timeline.");
                for (Status status : statuses) {
                    //                        System.out.println("Debug - text: " + status.getText());
                    saveToFile(status.getUser().getId(), status.getText().replaceAll("\n", "\\\\n"),
                            status.getUser().getScreenName(), listOfPeople.get(key));
                    //                        System.out.println("debug - truncated: " + status.isTruncated());
                }
            }
            if (statuses.size() < 1 || statuses == null) {
                continue;
            }
            Status temp = statuses.get(0);
            saveToFile(temp.getUser().getId(), temp.getUser().getScreenName(), listOfPeople.get(key));
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get timeline: " + te.getMessage());
            System.exit(-1);
        }
    }

}

From source file:com.mycompany.twitterapp.TwitterApp.java

public void getTweet() {

    Query query = new Query(tweetSearchWord);
    QueryResult result = null;/*from  w ww .java 2s .c  om*/
    try {
        result = twitter.search(query);
    } catch (TwitterException ex) {
        java.util.logging.Logger.getLogger(TwitterApp.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (result == null) {
        System.out.println("nope");
        return;
    }
    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
    }
}

From source file:com.mycompany.twitterproductanalysistool.TwitterAPI.java

public ArrayList<String> getQuery(String qry) {
    tweets = new ArrayList<>();
    tweetCountries = new ArrayList<>();
    tweetDates = new ArrayList<>();
    try {/*  ww  w . j  a v  a2  s  .  c  o  m*/
        Query query = new Query(qry);
        query.setCount(99);
        result = twitter.search(query);
        for (Status status : result.getTweets()) {
            tweets.add(status.getText());
            tweetDates.add(status.getCreatedAt());
            if (status.getUser() == null) {
                tweetCountries.add("NO COUNTRY");
            } else {
                tweetCountries.add(status.getUser().getLocation());
            }
        }
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
        System.exit(-1);
    }
    for (int i = 0; i < tweets.size(); i++) {
        String s = tweets.get(i);
        tweets.set(i, s.replace("\n", ""));
    }
    return tweets;
}

From source file:com.mycompany.twittersearch.SearchTwitter.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  w  w w. jav a 2  s. co m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, TwitterException {

    Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");
    out.println(twitter.toString());
    String searchItem = request.getParameter("term");

    try {
        Query query = new Query(searchItem);

        QueryResult result = twitter.search(query);

        List<Status> tweets = result.getTweets();
        String list = "";
        for (Status tweet : tweets) {
            list += "@" + tweet.getUser().getScreenName() + " - " + tweet.getText() + "<br>";
        }

        request.setAttribute("list", list);

    } catch (TwitterException te) {
        te.printStackTrace();
        out.println("Failed to search tweets: " + te.getMessage());
        System.exit(-1);
    }
    request.getRequestDispatcher("showTweets.jsp").forward(request, response);

}

From source file:com.mycompany.twittersearch.StatusListener.java

public void onStatus(Status status) {
    String list = "@" + status.getUser().getScreenName() + " - " + status.getText();
}

From source file:com.narvis.frontend.twitter.input.Input.java

License:Open Source License

private TwitterMessageInOut createMessageFromTweet(Status status) throws IllegalKeywordException {
    return new TwitterMessageInOut(this.accessTwitter.getConf().getName(), getCleanTweet(status.getText()),
            status.getUser().getScreenName() + getOtherResponseName(status.getText()), this.accessTwitter,
            status.getId());/*ww  w.j a va  2  s .  c  om*/
}