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:io.vertigo.adapters.twitter.TwitterAdapter.java

License:Apache License

public static void sendMessage(final String message) {
    try {//from   w  w w  . j a va 2  s. co m
        final Status status = TWITTER.updateStatus("Message from TwitterNotificationPlugin:" + message);
        LOGGER.info("Successfully updated the status to [{}].", status != null ? status.getText() : "");
    } catch (final TwitterException e) {
        LOGGER.error("Error while sending new status.", e);
        throw WrappedException.wrap(e);
    }
}

From source file:it.greenvulcano.gvesb.social.twitter.directcall.TwitterOperationBase.java

License:Open Source License

/**
 * @param parser//from   w  w  w .java 2 s  .c  o m
 * @param root
 * @param status
 * @throws XMLUtilsException
 */
protected void dumpTweet(XMLUtils parser, Element root, Status status) throws XMLUtilsException {
    Element tweet = parser.insertElement(root, "Tweet");
    parser.setAttribute(tweet, "id", String.valueOf(status.getId()));
    parser.setAttribute(tweet, "createdAt",
            DateUtils.dateToString(status.getCreatedAt(), DateUtils.FORMAT_ISO_DATETIME_UTC));
    parser.setAttribute(tweet, "fromUser", status.getUser().getScreenName());
    parser.setAttribute(tweet, "fromUserId", String.valueOf(status.getUser().getId()));
    parser.insertText(tweet, status.getText());
}

From source file:it.unipr.aotlab.TwitterMiner.twitter.client.TwitterStreamListener.java

License:Open Source License

/**
 * This method calls the update function of the database to store
 * informations about received tweets/*w w w . j  a  v a 2 s  .  co  m*/
 */
@Override
public void onStatus(Status status) {

    System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());

    hashtag = status.getHashtagEntities();
    mentions = status.getUserMentionEntities();

    redisDB.update(status.getUser().getScreenName(), hashtag, mentions);
}

From source file:JavaFiles.TwitterAPI.java

public Report getTweet(Report report, String keyword) {

    try {//from ww w  . j av a2  s. c  om
        Query query = new Query(keyword);
        QueryResult result = twitter.search(query);

        for (Status status : result.getTweets()) {
            report.setTweet(status.getText());
            report.setTweetID(status.getId());
            report.setUserID(status.getUser().getName());
        }
    } catch (TwitterException te) {
        te.printStackTrace();
    }
    return report;
}

From source file:jp.gihyo.wicket.page.ajax.AjaxTimeline.java

License:Apache License

private void constructPage() {
    final TweetForm form = new TweetForm("tweetForm");
    add(form);// ww w.j  a va 2s  . c om

    feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() {
        @Override
        protected List<Status> load() {
            try {
                Twitter twitter = AppSession.get().getTwitterSession();
                return twitter.getFriendsTimeline(new Paging(currentPageNumber, ITEMS_PER_PAGE));
            } catch (TwitterException ex) {
                AjaxTimeline.this.error(getString("canNotRetrieveFriendTimeline"));
                return Collections.emptyList();
            }
        }
    };

    ListView<Status> timeline = new ListView<Status>("statusView", statusModel) {
        @Override
        protected void populateItem(final ListItem<Status> item) {
            final Status status = item.getModelObject();
            String userUrl = "http://twitter.com/" + status.getUser().getScreenName();
            ExternalLink imageLink = new ExternalLink("imageLink", userUrl);

            //ImageR|?[lg?A<img>^Osrc??X`?X
            WebMarkupContainer userImage = new WebMarkupContainer("userImage");
            userImage.add(new SimpleAttributeModifier("src", status.getUser().getProfileImageURL().toString()));

            imageLink.add(userImage);
            item.add(imageLink);

            ExternalLink screenNameLink = new ExternalLink("screenName", userUrl,
                    status.getUser().getScreenName());
            item.add(screenNameLink);

            Label content = new Label("tweetContent", status.getText());
            item.add(content);

            ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null);
            item.add(tweetLink);

            Label time = new Label("tweetTime",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt()));
            tweetLink.add(time);

            Label clientName = new Label("clientName", status.getSource());
            item.add(clientName.setEscapeModelStrings(false));

            /*
             * YXe?[^XCo^\xNX?B
             * ?\bh?A??[JNX`?B
             * ??[JNX?ANXOstatus?ANZX?B
             */
            class FavorateLabel extends Label {
                private static final long serialVersionUID = -2194580825236126312L;
                private Status targetStatus;
                private boolean needRefresh;

                public FavorateLabel(String id) {
                    super(id);
                    this.targetStatus = status;

                    setDefaultModel(new AbstractReadOnlyModel<String>() {
                        @Override
                        public String getObject() {
                            try {
                                if (needRefresh) {
                                    targetStatus = getCurrentStatus(status.getId());
                                    needRefresh = false;
                                }
                                return targetStatus == null ? "" : targetStatus.isFavorited() ? "unfav" : "fav";
                            } catch (TwitterException ex) {
                                LOGGER.error("Can not fetch current status for status id = " + status.getId(),
                                        ex);
                                return "error";
                            }
                        }
                    });
                }

                public void setNeedRefresh(boolean needRefresh) {
                    this.needRefresh = needRefresh;
                }
            }

            //CNx
            final FavorateLabel favName = new FavorateLabel("favName");
            favName.setOutputMarkupId(true);

            /*
             * AjaxCN?B
             * Xe?[^XCo^o^?Ao^???s?B
             * o^???AAjaxg?Ay?[WS?ACo^Xe?[^X
             * Nx??B
             */
            AjaxLink<Void> favLink = new AjaxLink<Void>("favLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    try {
                        Status currentStatus = getCurrentStatus(status.getId());
                        Twitter twitterSession = AppSession.get().getTwitterSession();
                        if (currentStatus.isFavorited()) {
                            twitterSession.destroyFavorite(currentStatus.getId());
                            info(getString("favorateRemoved"));
                        } else {
                            twitterSession.createFavorite(currentStatus.getId());
                            info(getString("favorateRegistered"));
                        }
                        favName.setNeedRefresh(true);
                        target.addComponent(feedback); //o^?bZ?[W\?AtB?[hobNpl?X?V?B
                        target.addComponent(favName);
                    } catch (TwitterException ex) {
                        String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode();
                        error(message);
                        LOGGER.error(message, ex);
                    }
                }
            };
            item.add(favLink);
            favLink.add(favName);

            //AJAX LINK
            item.add(new AjaxLink<Void>("replyLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    String targetScreenName = status.getUser().getScreenName();
                    form.insertText(target, "@" + targetScreenName + " ");
                }
            });

            //Q?l?AreplyLinkJavaScriptp
            //                item.add(new Link<Void>("replyLink") {
            //                    @Override
            //                    public void onClick() {
            //                    }
            //
            //                    @Override
            //                    protected CharSequence getOnClickScript(CharSequence url) {
            //                        return "getElementById('" + form.getTextAreaId() + "').value = '@" + status.getUser().getScreenName() + " ';" +
            //                               "getElementById('" + form.getTextAreaId() + "').focus(); return false;";
            //                    }
            //                });
        }
    };

    //ListView\e?s????BreuseItemsv?peB??A
    //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B
    //twitterey?[We?X??AXg????AXge?
    //Xe?[^Xu?A??dv?B
    timeline.setReuseItems(true);
    add(timeline);

    /*
     * y?[WO?EirQ?[^
     */
    add(new PagingLink("paging", AjaxTimeline.class, new AbstractReadOnlyModel<Integer>() {
        @Override
        public Integer getObject() {
            return getCurrentPage();
        }
    }));
}

From source file:jp.gihyo.wicket.page.paging.PagingTimeline.java

License:Apache License

private void constructPage() {
    final TweetForm form = new TweetForm("tweetForm");
    add(form);//from w  w w . j a v a 2  s .  c  om

    feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    /*
     * ^CCpIModel?B
     * ??[hf?[^NGXg?EX|X?ETCNLbV?A
     * LoadableDetachableModelNXgp?B
     */
    IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() {
        @Override
        protected List<Status> load() {
            try {
                Twitter twitter = AppSession.get().getTwitterSession();
                return twitter.getFriendsTimeline(new Paging(currentPageNumber, ITEMS_PER_PAGE));
            } catch (TwitterException ex) {
                PagingTimeline.this.error(getString("canNotRetrieveFriendTimeline"));
                return Collections.emptyList();
            }
        }
    };

    /*
     * ^CCXg
     */
    ListView<Status> timeline = new ListView<Status>("statusView", statusModel) {
        @Override
        protected void populateItem(final ListItem<Status> item) {
            final Status status = item.getModelObject();
            String userUrl = "http://twitter.com/" + status.getUser().getScreenName();
            ExternalLink imageLink = new ExternalLink("imageLink", userUrl);

            //ImageR|?[lg?A<img>^Osrc??X`?X
            WebMarkupContainer userImage = new WebMarkupContainer("userImage");
            userImage.add(new SimpleAttributeModifier("src", status.getUser().getProfileImageURL().toString()));

            imageLink.add(userImage);
            item.add(imageLink);

            ExternalLink screenNameLink = new ExternalLink("screenName", userUrl,
                    status.getUser().getScreenName());
            item.add(screenNameLink);

            Label content = new Label("tweetContent", status.getText());
            item.add(content);

            ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null);
            item.add(tweetLink);

            Label time = new Label("tweetTime",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt()));
            tweetLink.add(time);

            Label clientName = new Label("clientName", status.getSource());
            item.add(clientName.setEscapeModelStrings(false));

            /*
             * CNx?BIModel?f?A?fav/unfav
             * \?B
             */
            final Label favName = new Label("favName", new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    return status.isFavorited() ? "unfav" : "fav";
                }
            });

            /*
             * CN?BNbN?C?E??s?B
             */
            Link<Void> favLink = new Link<Void>("favLink") {
                @Override
                public void onClick() {
                    try {
                        Twitter twitterSession = AppSession.get().getTwitterSession();
                        if (status.isFavorited()) {
                            twitterSession.destroyFavorite(status.getId());
                            info(getString("favorateRemoved"));
                        } else {
                            twitterSession.createFavorite(status.getId());
                            info(getString("favorateRegistered"));
                        }
                    } catch (TwitterException ex) {
                        String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode();
                        error(message);
                        LOGGER.error(message, ex);
                    }
                }
            };
            item.add(favLink);
            favLink.add(favName);

            /*
             * vCpN?B
             * ?u@screenName?v?B
             */
            item.add(new Link<Void>("replyLink") {
                @Override
                public void onClick() {
                    String targetScreenName = status.getUser().getScreenName();
                    form.insertText("@" + targetScreenName + " ");
                }
            });
        }
    };

    //ListView\e?s????BreuseItemsv?peB??A
    //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B
    //twitterey?[We?X??AXg????AXge?
    //Xe?[^Xu?A??dv?B
    timeline.setReuseItems(true);

    add(timeline);

    /*
     * y?[WO?EirQ?[^
     */
    add(new PagingLink("paging", PagingTimeline.class, new AbstractReadOnlyModel<Integer>() {
        @Override
        public Integer getObject() {
            return getCurrentPage();
        }
    }));
}

From source file:jp.gihyo.wicket.page.simple.MyTimeline.java

License:Apache License

private void constructPage() {
    final TweetForm form = new TweetForm("tweetForm");
    add(form);/*from ww  w . jav a2  s  .c om*/

    feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    /*
     * ^CCpIModel?B
     * ??[hf?[^NGXg?EX|X?ETCNLbV?A
     * LoadableDetachableModelNXgp?B
     */
    IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() {
        @Override
        protected List<Status> load() {
            try {
                Twitter twitter = AppSession.get().getTwitterSession();
                return twitter.getFriendsTimeline(new Paging(1, ITEMS_PER_PAGE));
            } catch (TwitterException ex) {
                MyTimeline.this.error(getString("canNotRetrieveFriendTimeline"));
                return Collections.emptyList();
            }
        }
    };

    /*
     * ^CCXg
     */
    ListView<Status> timeline = new ListView<Status>("statusView", statusModel) {
        @Override
        protected void populateItem(final ListItem<Status> item) {
            final Status status = item.getModelObject();
            String userUrl = "http://twitter.com/" + status.getUser().getScreenName();
            ExternalLink imageLink = new ExternalLink("imageLink", userUrl);
            byte[] byteArray = {};/* f?[^?? */
            UrlResourceStream stream = new UrlResourceStream(status.getUser().getProfileImageURL());
            try {
                stream.getInputStream().read(byteArray);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ResourceStreamNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Image userImage = new Image("userImage", new ByteArrayResource("image/jpeg", byteArray));
            imageLink.add(userImage);
            item.add(imageLink);

            ExternalLink screenNameLink = new ExternalLink("screenName", userUrl,
                    status.getUser().getScreenName());
            item.add(screenNameLink);

            Label content = new Label("tweetContent", status.getText());
            item.add(content);

            ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null);
            item.add(tweetLink);

            Label time = new Label("tweetTime",
                    new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt()));
            tweetLink.add(time);

            Label clientName = new Label("clientName", status.getSource());
            item.add(clientName.setEscapeModelStrings(false));

            /*
             * CNx?BIModel?f?A?fav/unfav
             * \?B
             */
            final Label favName = new Label("favName", new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    return status.isFavorited() ? "unfav" : "fav";
                }
            });

            /*
             * CN?BNbN?C?E??s?B
             */
            Link<Void> favLink = new Link<Void>("favLink") {
                @Override
                public void onClick() {
                    try {
                        Twitter twitterSession = AppSession.get().getTwitterSession();
                        if (status.isFavorited()) {
                            twitterSession.destroyFavorite(status.getId());
                            info(getString("favorateRemoved"));
                        } else {
                            twitterSession.createFavorite(status.getId());
                            info(getString("favorateRegistered"));
                        }
                    } catch (TwitterException ex) {
                        String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode();
                        error(message);
                        LOGGER.error(message, ex);
                    }
                }
            };
            item.add(favLink);
            favLink.add(favName);

            /*
             * vCpN?B
             * ?u@screenName?v?B
             */
            item.add(new Link<Void>("replyLink") {
                @Override
                public void onClick() {
                    String targetScreenName = status.getUser().getScreenName();
                    form.insertText("@" + targetScreenName + " ");
                }
            });
        }
    };
    //ListView\e?s????BreuseItemsv?peB??A
    //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B
    //twitterey?[We?X??AXg????AXge?
    //Xe?[^Xu?A??dv?B
    timeline.setReuseItems(true);

    add(timeline);
}

From source file:jp.wda.azeda.core.daemons.impl.RetweetsCrawlerImpl.java

License:Apache License

/**
 *
 *///from   w  ww . ja  v  a 2s .  c o m
@Aspect("aop.requiredTx")
public void crawl() throws TwitterException {
    log.debug("crawl retweets!!" + tweets.size());
    if (tweets.size() == 0) {
        loadTweets();
    }
    if (tweets.size() == 0) {
        return;
    }

    RetweetedTweet tweet = tweets.remove(0);
    log.debug("check tweet " + tweet.getTweetID());

    Twitter twitter = new TwitterFactory().getInstance();
    AccessToken accessToken = new AccessToken(tweet.getAccessToken().getAccessToken(),
            tweet.getAccessToken().getAccessTokenSecret());
    twitter.setOAuthAccessToken(accessToken);

    ResponseList<Status> rt = getRetweets(twitter, tweet.getTweetID());
    if (!alive) {
        return;
    }
    if (rt == null || rt.size() == 0) {
        return;
    }

    HashMap<Long, Status> retweets = new HashMap<Long, Status>();
    for (Status status : rt) {
        retweets.put(status.getUser().getId(), status);
    }

    List<Retweeter> registered = retweetersDao.getRetweeterIDs(tweet.getTweetID());
    for (Retweeter retweeter : registered) {
        long registeredUserID = retweeter.getRetweeterID();
        if (retweets.containsKey(registeredUserID)) {
            retweets.remove(registeredUserID);
            continue;
        }
    }
    if (retweets.size() == 0) {
        return;
    }

    for (Status status : retweets.values()) {
        long retweeter = status.getUser().getId();
        long oldest = System.currentTimeMillis() - retweetExpired * 60 * 1000L;
        if (status.getCreatedAt().getTime() < oldest) {
            log.info(tweet.getTweetID() + " retweet by " + status.getUser().getScreenName() + " ? "
                    + retweetExpired + "?????????");
            insertRetweeter(twitter.getId(), tweet.getTweetID(), retweeter);
            continue;
        }

        List<Status> userTimeline = loadRetweetersTweets(twitter, tweet.getTweetID(), retweeter, 1);
        if (!alive) {
            return;
        }
        if (userTimeline == null) {
            continue;
        }

        int skips = 0;
        for (int i = userTimeline.size() - 1; i >= 0; i--) {
            Status s = userTimeline.get(i);
            UserMentionEntity[] mentions = s.getUserMentionEntities();
            if (s.isRetweet()) {
                skips++;
                continue;
            }
            if (mentions == null || mentions.length > 0) {
                skips++;
                continue;
            }

            log.debug(s.getId() + ":" + s.getCreatedAt() + "(" + s.isRetweet() + ") " + s.getText());

            Retweet retweet = new Retweet();
            retweet.setTweetID(s.getId());
            retweet.setRetweetTo(tweet.getTweetID());
            retweet.setRetweeterID(retweeter);
            retweet.setTweettext(s.getText());
            retweet.setCreatedat(new Timestamp(s.getCreatedAt().getTime()));
            retweet.setSkiptweets(skips);
            retweet.setScreenName(status.getUser().getScreenName());
            dtoRetweets.add(retweet);

            insertRetweeter(twitter.getId(), tweet.getTweetID(), retweeter);
            break;
        }
    }

    register();
}

From source file:jp.wda.azeda.core.daemons.impl.UserCrawlerImpl.java

License:Apache License

/**
 *
 *///from w w w.  java  2 s.  c om
@Aspect("aop.requiredTx")
public void crawl() throws TwitterException {
    StoredAccessToken storedAccessToken = accessTokensDao.getAccessTokenByUserID(userID);
    if (storedAccessToken == null) {
        return;
    }
    if (!alive) {
        return;
    }
    log.debug("crawl user retweets!!");

    Twitter twitter = new TwitterFactory().getInstance();
    AccessToken accessToken = new AccessToken(storedAccessToken.getAccessToken(),
            storedAccessToken.getAccessTokenSecret());
    twitter.setOAuthAccessToken(accessToken);

    List<Status> retweets = twitter.getRetweetsOfMe();
    if (!alive) {
        return;
    }

    List<RetweetedTweet> registered = dao.getAll(userID,
            new Timestamp(System.currentTimeMillis() - 365 * 24 * 60 * 60 * 1000L));
    List<Long> registeredIDs = new ArrayList<Long>();
    for (RetweetedTweet t : registered) {
        registeredIDs.add(t.getTweetID());
    }
    if (!alive) {
        return;
    }

    List<RetweetedTweet> dtos = new ArrayList<RetweetedTweet>();
    long oldest = System.currentTimeMillis() - expired * 24 * 60 * 60 * 1000L;
    for (Status s : retweets) {
        if (registeredIDs.contains(s.getId())) {
            continue;
        }
        if (s.getCreatedAt().getTime() < oldest) {
            continue;
        }

        RetweetedTweet dto = new RetweetedTweet();
        dto.setTweetID(s.getId());
        dto.setUserID(userID);
        dto.setTweettext(s.getText());
        dto.setCreatedat(new Timestamp(s.getCreatedAt().getTime()));
        dtos.add(dto);
    }
    if (!alive) {
        return;
    }
    dao.insertBatch(dtos);
}

From source file:Jums.SearchTweets.java

License:Apache License

/**
 * Usage: java twitter4j.examples.search.SearchTweets [query]
 *
 * @param args search query/* ww w  .j av  a2  s  .  c o  m*/
 */
public void main(String args) {
    System.out.println("java twitter4j.examples.search.SearchTweets [query]");
    System.exit(-1);

    Twitter twitter = new TwitterFactory().getInstance();
    try {
        Query query = new Query(args);
        QueryResult result;
        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            for (Status tweet : tweets) {
                System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
            }
        } while ((query = result.nextQuery()) != null);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
        System.exit(-1);
    }
}