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:kerguelenpetrel.RespondServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    StringBuilder builder = new StringBuilder();
    resp.setContentType("text/plain; charset=UTF-8");

    try {/*from w  w  w  .ja  v a 2s  . c  om*/
        //Get the Twitter object
        Twitter twit = TwitterFactory.getSingleton();
        ResponseList<Status> mentions = twit.getMentionsTimeline();

        lastPostIdEntity = datastore.get(KeyFactory.createKey("lastPostIDEntity", "ID"));
        lastPostId = Long.parseLong(lastPostIdEntity.getProperty("lastPostID").toString());

        if (mentions.size() == 0) {
            resp.getWriter().println("No mentions so far...\n");
            return;
        }

        for (Status mention : mentions) {
            if (lastPostId < mention.getId()) {
                if (mention.getUser().getId() == twit.getId())
                    ; //don't respond to myself

                else if (mention.isRetweeted())
                    mention = twit.createFavorite(mention.getId()); //mark the retweet as a favourite
                else if (mention.getText().toLowerCase().contains("bye")) {
                    builder.setLength(0);
                    builder.append("@");
                    builder.append(mention.getUser().getScreenName());
                    builder.append(" Bye");
                } else {
                    builder.setLength(0);
                    //Add the screen name of the person we are responding to
                    builder.append("@");
                    builder.append(mention.getUser().getScreenName() + " ");

                    //Get feed title as content
                    builder.append(getFeedTitle(resp));

                    //Get a Wordnik trend
                    builder.append(getWordnikTrend(resp));

                    /* Tweets are maximum 280 characters */
                    if (builder.length() > 280) {
                        builder.setLength(builder.lastIndexOf(" ", 270));
                        builder.append(end[(r.nextInt(end.length))]);
                    }
                }
                //Set the status
                StatusUpdate status = new StatusUpdate(builder.toString());

                //Post the status
                twit.updateStatus(status);
                resp.getWriter().println("Tweet posted: " + status.getStatus());
            }
        }
        //Save last post ID
        lastPostIdEntity.setProperty("lastPostID", (Long.toString(mentions.get(0).getId())));
        datastore.put(lastPostIdEntity);
    } catch (EntityNotFoundException e) {
        // Make new ResponseIDentity
        lastPostIdEntity = new Entity("lastPostIDEntity", "ID");
        lastPostIdEntity.setProperty("lastPostID", "0");
        datastore.put(lastPostIdEntity);
        resp.getWriter()
                .println("Made new lastPostId " + lastPostIdEntity.getProperty("lastPostID").toString());
    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter \n");
        e.printStackTrace(resp.getWriter());
    }
}

From source file:keypoh.TwitterCrawler.java

/**
 * Function getTimeline//  w  w  w. j a v a 2 s.co m
 * @param key
 * @return List
 * @throws Exception 
 */
private List getTimeline(String key) throws Exception {
    List<String> ans = new LinkedList();
    Query query = new Query(key);
    query.setCount(limit);
    QueryResult res = tw.search(query);

    List<Status> tweets = res.getTweets();
    for (Status tweet : tweets) {
        if (tweet.getText() != null) {
            ans.add(tweet.getText());
        }
    }

    return ans;
}

From source file:kr.debop4j.search.twitter.Twitters.java

License:Apache License

public static Twit createTwit(Status status) {
    Twit twit = new Twit();
    twit.setId(status.getId());//from  www  .  j  a va2s  . c om
    twit.setUsername(status.getUser().getName());
    twit.setText(status.getText());
    twit.setCreatedAt(status.getCreatedAt());
    return twit;
}

From source file:libreriatwitter.Metodos.java

/**
 * Muestra el timeline//from www.j  av  a 2s .c  o m
 * @throws twitter4j.TwitterException
 */
public void verTimeLine() throws TwitterException {

    ResponseList<twitter4j.Status> statuses = twitter.getHomeTimeline();
    System.out.println("Showing home timeline.");
    for (twitter4j.Status status : statuses) {
        System.out.println(status.getUser().getName() + ":" + status.getText());
    }

}

From source file:libreriatwitter.Metodos.java

/**
 * Buscador de Tweets//from   w w  w.j  ava  2 s  .  c  om
 * @param buscar
 * @throws twitter4j.TwitterException
 */
public void buscarTweet(String buscar) throws TwitterException {

    Query query = new Query(buscar);
    QueryResult result = twitter.search(query);
    for (twitter4j.Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
    }

}

From source file:libreriatwitter.Metodos.java

/**
 * Crea y publica un tweet/*from   w  w  w .ja v a2 s  .  c  om*/
 * @param tweet
 * @throws twitter4j.TwitterException
 */
public void escribirTweet(String tweet) throws TwitterException {

    twitter4j.Status status = twitter.updateStatus(tweet);
    System.out.println("Successfully updated the status to [" + status.getText() + "].");

}

From source file:Logic.mongoC.java

public boolean inicioSesion() {
    /*Entro a twitter con una cuenta de un suario x
    para esto necesite los permisos que esta abajo*/

    /*Permisos de la cuenta a la que ingreso*/

    /*Trata de hacer la conexion con twitter
    y toma los ultimos 20 twitts que aparecen en la 
    time line del usuario*///from  w  ww .j  a  v a 2s.c  o m
    conect();
    try {

        twitter4j.User user = twitter.verifyCredentials();
        List<Status> statu = twitter.getHomeTimeline();
        for (Status sta : statu) {
            System.out.println("Showing @" + sta.getUser().getScreenName() + "->" + sta.getText());
        }

        //usuario("sofimelgar_",cb,twitter);
        return true;
    } catch (TwitterException ex) {

        return false;
    }

}

From source file:Logic.mongoC.java

public void IngresarUsuario(String name) {

    String[] buscarUs = new String[1];
    buscarUs[0] = name;/*from w  w  w  . j  ava  2  s  .  c o  m*/
    try {
        ResponseList<twitter4j.User> use = twitter.lookupUsers(buscarUs);
        twitter4j.User u = use.get(0);
        System.out.println(u.getStatus());
        usuario nuevoS = new usuario();
        nuevoS.setId(Long.toString(u.getId()));
        nuevoS.setNombre(u.getName());
        nuevoS.setLocation(u.getLocation());
        nuevoS.setNumFol(u.getFollowersCount());
        nuevoS.setNumeroDeT(u.getStatusesCount());
        List<Status> twitts = twitter.getUserTimeline(u.getId(), new Paging(1, 200));
        ArrayList<twitt> timeL = new ArrayList();
        for (Status s : twitts) {
            twitt tw = new twitt();
            tw.setTexto(s.getText());
            tw.setRetwett(s.getRetweetCount());
            //tw.setFecha((java.util.Date) s.getCreatedAt());
            tw.setFav(s.getFavoriteCount());
            tw.setCreador(s.getUser().getScreenName());
            UserMentionEntity[] userMentionEntities = s.getUserMentionEntities();
            ArrayList<String> inter = new ArrayList();
            for (UserMentionEntity uh : userMentionEntities) {
                inter.add(uh.getScreenName());
            }
            tw.setPersonas(inter);
            timeL.add(tw);
        }
        nuevoS.setTimeline(timeL);
        final String fIns = gson.toJson(nuevoS);

        Document dt;
        dt = new Document("ScreenName", u.getScreenName());
        dt.append("todo", fIns);
        conect();
        coll.insertOne(dt);
        JOptionPane.showMessageDialog(null, "Usuario Ingresado");
    }

    catch (TwitterException ex) {
        System.out.println("No se pudo conectar el usuario deseado");
    }

}

From source file:main.TwitterController.java

License:Open Source License

public void listMentions() throws TwitterException {
    int counter = 0;
    List<Status> mentions = twitter.getMentions();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Iterator<Status> iterator = mentions.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;//from  w  ww  . j  av  a 2s .  co 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:main.TwitterController.java

License:Open Source License

public void getMyTimeline() throws TwitterException {
    int counter = 0;
    List<Status> statusList = twitter.getUserTimeline();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Iterator<Status> iterator = statusList.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + s.getText());
        if (counter == 10) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;//w  w w . ja v  a2  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;
        }
    }
}