Example usage for twitter4j Paging Paging

List of usage examples for twitter4j Paging Paging

Introduction

In this page you can find the example usage for twitter4j Paging Paging.

Prototype

public Paging(int page, long sinceId) 

Source Link

Usage

From source file:info.maslowis.twitterripper.command.impl.twitter.TimelineGetName.java

License:Open Source License

@Override
public void execute() throws ExecuteCmdException {
    try {/*from   w  w w.j a va 2  s  .c o  m*/
        ResponseList<Status> statuses = twitter.getUserTimeline(name, new Paging(page, count));
        if (statuses.isEmpty()) {
            out.println("No statuses");
        } else {
            for (Status status : statuses) {
                out.println(Util.toString(status));
            }
        }
    } catch (TwitterException e) {
        throw new ExecuteCmdException(e);
    }
}

From source file:info.maslowis.twitterripper.command.impl.twitter.TweetDeleteAll.java

License:Open Source License

@Override
public void execute() throws ExecuteCmdException {
    try {/*from www . j ava 2  s .co m*/
        out.println(ansi().a(Attribute.INTENSITY_BOLD).fg(Color.RED)
                .a("This command delete all yours statuses! You want to continue? [yes/no]").reset());
        String input = Application.INSTANCE.getReader().readLine();
        if (input.trim().equalsIgnoreCase("yes")) {
            try {
                int page = 1;
                final int count = 200;
                Paging paging = new Paging(page, count);
                ResponseList<Status> statuses = twitter.getUserTimeline(twitter.getId(), paging);
                while (!statuses.isEmpty()) {
                    for (Status status : statuses) {
                        twitter.destroyStatus(status.getId());
                        out.println("You now deleted " + Util.toString(status));
                    }
                    page++;
                    paging = new Paging(page, count);
                    statuses = twitter.getUserTimeline(twitter.getId(), paging);
                }
            } catch (TwitterException e) {
                throw new ExecuteCmdException(e);
            }
        } else {
            out.println("Command was cancelled");
        }
    } catch (IOException e) {
        logger.error("Error reading input", e);
        exit(-1);
    }
}

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

License:Apache License

private void constructPage() {
    final TweetForm form = new TweetForm("tweetForm");
    add(form);/*from w  w  w.  j a v  a2s. c o m*/

    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.ajax.AjaxTimeline.java

License:Apache License

protected Status getCurrentStatus(long statusId) throws TwitterException {
    Twitter twitterSession = AppSession.get().getTwitterSession();
    Paging paging = new Paging(1, 1);
    paging.setMaxId(statusId);//from   ww w  .  j  ava  2 s.com
    List<Status> statusList = twitterSession.getFriendsTimeline(paging);
    return statusList.size() > 0 ? statusList.get(0) : null;
}

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

License:Apache License

private void constructPage() {
    final TweetForm form = new TweetForm("tweetForm");
    add(form);/* w  ww. j  a  va2 s. com*/

    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   www  .  j  a v a  2s  .  c  o  m*/

    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:Logic.mongoC.java

public void IngresarUsuario(String name) {

    String[] buscarUs = new String[1];
    buscarUs[0] = name;// w  w w  .j a va 2 s  . co  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:nl.isaac.dotcms.twitter.util.TwitterUtil.java

License:Creative Commons License

/**
 * Get tweets from current User/*from ww w . ja  v a2 s  .co  m*/
 * @param count
 * @return
 */
public List<CustomStatus> getUserTimeline(int count) {
    List<CustomStatus> statuses = new ArrayList<CustomStatus>();

    try {
        statuses = formatStatus(twitter.getUserTimeline(new Paging(1, count)));
    } catch (TwitterException e) {
        throw new RuntimeException(e.toString(), e);
    }
    return statuses;
}

From source file:nl.isaac.dotcms.twitter.util.TwitterUtil.java

License:Creative Commons License

/**
 * Get tweets for given screenname User//from   w w w.  j ava2s.co m
 * @param count
 * @return
 */
public List<CustomStatus> getUserTimeline(String screenname, int count) {
    List<CustomStatus> statuses = new ArrayList<CustomStatus>();

    try {
        statuses = formatStatus(twitter.getUserTimeline(screenname, new Paging(1, count)));
    } catch (TwitterException e) {
        throw new RuntimeException(e.toString(), e);
    }
    return statuses;
}

From source file:org.apache.streams.twitter.provider.TwitterTimelineProviderTask.java

License:Apache License

@Override
public void run() {

    Paging paging = new Paging(1, 200);
    List<Status> statuses = null;

    do {/*ww w. j  a v  a 2 s .  co m*/
        int keepTrying = 0;

        // keep trying to load, give it 5 attempts.
        //This value was chosen because it seemed like a reasonable number of times
        //to retry capturing a timeline given the sorts of errors that could potentially
        //occur (network timeout/interruption, faulty client, etc.)
        while (keepTrying < 5) {

            try {
                this.client = provider.getTwitterClient();

                statuses = client.getUserTimeline(id, paging);

                for (Status tStat : statuses) {
                    String json = TwitterObjectFactory.getRawJSON(tStat);

                    provider.addDatum(new StreamsDatum(json));

                }

                paging.setPage(paging.getPage() + 1);

                keepTrying = 10;
            } catch (TwitterException twitterException) {
                keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
            } catch (Exception e) {
                keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
            }
        }
    } while (provider.shouldContinuePulling(statuses));

    LOGGER.info(id + " Thread Finished");

}