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:fr.istic.taa.jaxrs.TweetEndpoint.java

License:Apache License

@GET
@Path("/status")
@Produces(MediaType.TEXT_PLAIN)//  w  w w.j a  v  a2 s .  com
public String getStatus() {

    try {
        String result_l = "";
        for (Status status_l : link.getHomeTimeline()) {
            result_l += status_l.getText() + "\n";
        }
        return result_l;
    } catch (TwitterException e) {
        logger.error(e.getMessage(), e);
    }

    return "Erreur lors de la rcupration des tweets";

}

From source file:fr.ybo.transportsrennes.adapters.TwitterAdapter.java

License:Open Source License

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;// ww w  .j a  v a2s . c  o  m
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.onetwitter, null);
        holder = new ViewHolder();
        holder.twitter = (TextView) convertView.findViewById(R.id.twitter);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Status status = allStatus.get(position);
    holder.twitter.setText(SDF.format(status.getCreatedAt()) + status.getText());
    return convertView;
}

From source file:fr.ybonnel.model.TweetPhoto.java

License:Apache License

public static Stream<TweetPhoto> fromStatus(Status status) {
    String user = status.getUser().getScreenName();
    String avatar = status.getUser().getBiggerProfileImageURL();
    String text = status.getText();
    /*if (status.getMediaEntities().length == 0) {
    return Stream.of(new TweetPhoto(user, avatar, "http://placehold.it/400x300", text));
    }*///from w ww.j a v  a  2  s  . c  o  m
    return Arrays.stream(status.getMediaEntities())
            .map(media -> new TweetPhoto(user, avatar, media.getMediaURL(), text));
}

From source file:fr.ybonnel.modele.TweetPhoto.java

License:Apache License

public static Stream<TweetPhoto> fromStatus(Status status) {
    String user = status.getUser().getScreenName();
    String avatar = status.getUser().getBiggerProfileImageURL();
    String text = status.getText();
    return Arrays.stream(status.getMediaEntities()).map(MediaEntity::getMediaURL)
            .map(url -> new TweetPhoto(user, avatar, url, text));
}

From source file:free.chessclub.bot.TwitterManager.java

License:Apache License

public void tweet(String tweet) throws TwitterException {
    Status status = twitter.updateStatus(tweet);
    System.out.println("Successfully updated the status to [" + status.getText() + "].");
}

From source file:gh.polyu.user.TrackUsers.java

License:Apache License

public void track(final int no, final int p) {
    final TwitterDBHandle handle = new TwitterDBHandle();
    handle.intialTwitterDBhandle();/*from w ww . j a v  a 2  s.  c  o  m*/

    while (alive) {
        alive = false;
        StatusListener listener = new StatusListener() {
            ArrayList<_TweetLink> listlink = new ArrayList<_TweetLink>();
            int cnt = 0;
            String oldmonth = "20138";
            String table = "UserTweet20138";
            String oldday = "";
            String currentday = "";
            String currentmonth = "";
            long lastinsert = 0l;
            long nowinsert = 0l;
            int newday = 0;
            String newtime = "";

            @Override

            public void onStatus(Status status) {
                if (status.getId() == 123 && status.getText().equals("YOU are WORNG!.")) {
                    System.out.println("Connection Need to be rebuilt!!");
                    alive = true;
                } else if (status.getLang().equals("en")) {
                    _TweetLink tweet = new _TweetLink();
                    String Test = status.getText();
                    tweet.setText(Test);
                    Date time = status.getCreatedAt();
                    tweet.setTime(time);
                    tweet.setUserName(status.getUser().getName());
                    HashtagEntity[] hashtagentity = status.getHashtagEntities();
                    StringBuffer hashen = new StringBuffer();
                    for (int i = 0; i < hashtagentity.length; i++) {
                        hashen.append(hashtagentity[i].getText());
                        hashen.append(";");

                    }
                    tweet.setHashtag(hashen.toString());

                    URLEntity[] URLEn = status.getURLEntities();
                    StringBuffer URL = new StringBuffer();
                    for (int i = 0; i < URLEn.length; i++) {
                        URL.append(URLEn[i].getURL());
                        URL.append(";");

                    }
                    tweet.setURL(URL.toString());

                    //user mention
                    UserMentionEntity[] userEn = status.getUserMentionEntities();
                    StringBuffer mentuser = new StringBuffer();
                    for (int i = 0; i < userEn.length; i++) {
                        mentuser.append(userEn[i].getId());
                        mentuser.append(";");
                    }
                    tweet.setUerMention(mentuser.toString());
                    //if(mentuser.length()!=0);
                    //System.out.println("mentuser: "+ mentuser);
                    //tweetID
                    tweet.setTweetID(status.getId());
                    //if(ID!=null)
                    // original twitterID
                    tweet.setOriginID(status.getInReplyToStatusId());
                    //original user ID
                    tweet.setOriginUser(status.getInReplyToUserId());

                    // user ID

                    User users = status.getUser();
                    tweet.setTweetUser(users.getId());

                    //places
                    Place Pl = status.getPlace();
                    String place = "";
                    if (Pl != null) {
                        place = Pl.getFullName();
                        //System.out.println("place "+place);
                    }
                    tweet.setPlace(place);
                    // Retweetcoun
                    long num = 0;
                    if (status.getRetweetedStatus() != null) {
                        num = status.getRetweetedStatus().getRetweetCount();
                        //System.out.println("retweetcount"+num);
                        tweet.setRetweetCount(num);
                        tweet.setRetweet(1);
                    } else {
                        tweet.setRetweetCount(0);
                        tweet.setRetweet(0);
                    }
                    //   if(Retweet!=null)

                    //System.out.println("Retweetcount: "+ Retweet);

                    //isfavourate
                    boolean favourate = status.isFavorited();
                    /*if(favourate)
                    {
                    fav = 1;
                    tweet.setFavourate(fav);
                    fav =0;
                    System.out.println("isf "+ fav);
                    }*/

                    // is retweet

                    //String other = status.toString();
                    // tweet.setOther(other);
                    listlink.add(tweet);
                    Calendar cal = Calendar.getInstance();
                    int year = cal.get(Calendar.YEAR);
                    int month = cal.get(Calendar.MONTH) + 1;
                    int day = cal.get(Calendar.DAY_OF_MONTH);
                    currentmonth = String.valueOf(year) + String.valueOf(month);
                    currentday = String.valueOf(day);
                    if (currentmonth.equals(oldmonth)) {
                        if (currentday.equals(oldday))
                            ;
                        else {
                            newday = 1;
                            SimpleDateFormat formatter = new SimpleDateFormat("MMddHH:mm:ss ");
                            Date curDate = new Date(System.currentTimeMillis());//     
                            newtime = formatter.format(curDate);
                        }
                    } else {
                        try {
                            handle.database_connection();
                            table = "UserTweet" + String.valueOf(year) + String.valueOf(month);
                            System.out.println("create new table " + table);
                            String CREATE_TABLE = "create table " + table
                                    + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime,"
                                    + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))";
                            Statement st = handle.conn.createStatement();
                            st.execute(CREATE_TABLE);
                            String Create_Index = "alter table " + table + " add index time (Time)";
                            st.execute(Create_Index);
                            String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)";
                            st.execute(Create_Index2);
                            String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)";
                            st.execute(key);
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                        handle.close_databasehandle();
                        try {
                            TwitterDBHandle handle2 = new TwitterDBHandle();
                            handle2.intialTwitterDBhandle2();
                            handle2.database_connection();
                            table = "UserTweet" + String.valueOf(year) + String.valueOf(month);
                            System.out.println("create new table " + table);
                            String CREATE_TABLE = "create table " + table
                                    + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime,"
                                    + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))";
                            Statement st = handle2.conn.createStatement();
                            st.execute(CREATE_TABLE);
                            String Create_Index = "alter table " + table + " add index time (Time)";
                            st.execute(Create_Index);
                            String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)";
                            st.execute(Create_Index2);
                            String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)";
                            st.execute(key);
                            handle2.close_databasehandle();
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                    //System.out.println("OTHER: "+ other);

                    if ((cnt++) % 1000 == 0) {

                        if (newday == 1) {
                            newday = 0;
                            oldday = currentday;
                            GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy");
                            gs.send("THREAD" + p + " :" + "program no" + no + "message" + newtime,
                                    "I am still alive");
                            newtime = "";
                        }

                        try {
                            handle.database_connection();
                            handle.userTweet(table, listlink);
                            nowinsert = System.currentTimeMillis();
                            System.err.println(
                                    "No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n"
                                            + new Date(nowinsert) + "  " + new Date(lastinsert));
                            lastinsert = nowinsert;
                            nowinsert = 0l;
                            handle.close_databasehandle();
                        } catch (SQLException e) {
                            handle.close_databasehandle();
                            e.printStackTrace();
                            // TODO Auto-generated catch block
                            TwitterDBHandle handle2 = new TwitterDBHandle();
                            handle2.intialTwitterDBhandle2();
                            handle2.database_connection();

                            try {
                                handle2.userTweet(table, listlink);
                                nowinsert = System.currentTimeMillis();
                                System.err.println("New Database No: " + no + "program " + "totally " + cnt
                                        + " tweets downloaded!\n" + new Date(nowinsert) + new Date(lastinsert));
                                lastinsert = nowinsert;
                                nowinsert = 0l;
                                handle2.close_databasehandle();
                            } catch (SQLException e1) {
                                // TODO Auto-generated catch block
                                GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy");
                                try {
                                    gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error",
                                            "both databases are down");
                                } catch (MessagingException ee) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                            GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy");
                            try {
                                gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error",
                                        "change database to another one");
                            } catch (MessagingException ee) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        listlink.clear();
                    }
                }
            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
                //System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
            }

            @Override
            public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
                //System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
            }

            @Override
            public void onScrubGeo(long userId, long upToStatusId) {
                //System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
            }

            @Override
            public void onStallWarning(StallWarning warning) {
                //System.out.println("Got stall warning:" + warning);
            }

            @Override
            public void onException(Exception ex) {
                ex.printStackTrace();

            }
        };
        TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
        twitterOAuth twtOauth = new twitterOAuth();
        twtOauth.AuthoritywithS(twitterStream, key);
        twitterStream.addListener(listener);
        twitterStream.filter(new FilterQuery(0, follow));

        /*  try {
           Thread.sleep(3000);
                   
        } catch (InterruptedException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
        }*/
    }
}

From source file:gov.nasa.jpl.memex.elwha.impl.ElwhaResource.java

License:Apache License

/**
 * Main entry of this application./*from  ww w .  j  a  v a 2s.  c o  m*/
 *
 * @param userIds follow(comma separated user ids) track(comma separated filter terms)
 * @throws TwitterException when Twitter service or network is unavailable
 * @return
 */
@Override
public Elwha get(String userIds) {
    //return new Elwha().setMessage("Hello, Rest.li!");
    // }

    //if (userIds.length < 1) {
    //  System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]");
    //  System.exit(-1);
    //}

    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addListener(listener);
    ArrayList<Long> follow = new ArrayList<Long>();
    ArrayList<String> track = new ArrayList<String>();
    if (isNumericalArgument(userIds)) {
        for (String id : userIds.split(",")) {
            follow.add(Long.parseLong(id));
        }
    } else {
        track.addAll(Arrays.asList(userIds.split(",")));
    }
    long[] followArray = new long[follow.size()];
    for (int i = 0; i < follow.size(); i++) {
        followArray[i] = follow.get(i);
    }
    String[] trackArray = track.toArray(new String[track.size()]);

    // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    twitterStream.filter(new FilterQuery(0, followArray, trackArray));

    return new Elwha().setUserIds("Mock stub!");
}

From source file:Group5.Model.java

public static void Tweet(String inputTweet) throws TwitterException {
    //Your Twitter App's Consumer Key
    String consumerKey = "wK7lQLpl3t8xvIABqpgoJzYYd";

    //Your Twitter App's Consumer Secret
    String consumerSecret = "4M5TgmNfS0EKeaSqna8eHTNaNi970Plq3dynX5gvYsh848j0mj";

    //Your Twitter Access Token
    String accessToken = "829891753473892361-7jkKyXLYc6HOStzCPGjWOnVoAVNU7cd";

    //Your Twitter Access Token Secret
    String accessTokenSecret = "ATidrzRzhVqAamuMbYiskcHBPSisB9MWsCsYYY2Bec4y9";

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory();

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance();
    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

    //Instantiate and initialize a new twitter status update
    StatusUpdate statusUpdate = new StatusUpdate(
            //your tweet or status message
            inputTweet);//from  w w  w.  j  av  a  2s. c  o m

    //tweet or update status
    Status status = twitter.updateStatus(statusUpdate);

    //response from twitter server
    System.out.println("status.toString() = " + status.toString());
    System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
    System.out.println("status.getSource() = " + status.getSource());
    System.out.println("status.getText() = " + status.getText());

    System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
    System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
}

From source file:Group5.Model.java

public static List GetTimeline() throws TwitterException {
    //Your Twitter App's Consumer Key
    String consumerKey = "wK7lQLpl3t8xvIABqpgoJzYYd";

    //Your Twitter App's Consumer Secret
    String consumerSecret = "4M5TgmNfS0EKeaSqna8eHTNaNi970Plq3dynX5gvYsh848j0mj";

    //Your Twitter Access Token
    String accessToken = "829891753473892361-7jkKyXLYc6HOStzCPGjWOnVoAVNU7cd";

    //Your Twitter Access Token Secret
    String accessTokenSecret = "ATidrzRzhVqAamuMbYiskcHBPSisB9MWsCsYYY2Bec4y9";

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory();

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance();
    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
    List<Status> statuses = twitter.getHomeTimeline();
    System.out.println("Showing home timeline.");
    for (Status status : statuses) {
        System.out.println(status.getUser().getName() + ":" + status.getText());
    }/*from   w  w w .j  ava  2s . com*/
    return statuses;
}

From source file:gui.project.v3.FXMLDocumentController.java

@FXML
public void btn(ActionEvent event) {
    twitter = tf.getInstance();/*from   w  ww . j ava2  s.co m*/
    String[] fields = { ch1.getText(), ch2.getText(), ch3.getText(), ch4.getText(), ch5.getText(),
            ch6.getText(), ch7.getText(), ch8.getText(), ch9.getText(), ch10.getText() };
    int[] amount = new int[10];
    for (int i = 0; i < 10; i++) {
        amount[i] = 0;
    }
    Query query = new Query(parent.getText());
    query.setLang("en");
    QueryResult result;
    int number = 0;
    try {
        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            number += tweets.size();
            for (Status tweet : tweets) {
                String tweetText = tweet.getText();
                System.out.println(tweetText);
                for (int i = 0; i < 10; i++) {
                    if ((tweetText.startsWith(fields[i] + " ") || (tweetText.endsWith(" " + fields[i])
                            || tweetText.contains(" " + fields[i] + " "))) && fields[i].length() > 0) {
                        amount[i]++;
                    }
                }
            }
        } while ((query = result.nextQuery()) != null);
    } catch (TwitterException ex) {
    }

    ObservableList<PieChart.Data> list = FXCollections.observableArrayList();

    for (int i = 0; i < 10; i++) {
        if (fields[i].length() > 0) {
            list.add(new PieChart.Data(fields[i], amount[i]));

        }
        switch (i) {
        case 0:
            lab1.setText("" + amount[i]);
            break;
        case 1:
            lab2.setText("" + amount[i]);
            break;
        case 2:
            lab3.setText("" + amount[i]);
            break;
        case 3:
            lab4.setText("" + amount[i]);
            break;
        case 4:
            lab5.setText("" + amount[i]);
            break;
        case 5:
            lab6.setText("" + amount[i]);
            break;
        case 6:
            lab7.setText("" + amount[i]);
            break;
        case 7:
            lab8.setText("" + amount[i]);
            break;
        case 8:
            lab9.setText("" + amount[i]);
            break;
        case 9:
            lab10.setText("" + amount[i]);
            break;
        default:
            System.out.print(" ");
        }
    }
    chart.setData(list);
}