Example usage for twitter4j Twitter getRetweetsOfMe

List of usage examples for twitter4j Twitter getRetweetsOfMe

Introduction

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

Prototype

ResponseList<Status> getRetweetsOfMe() throws TwitterException;

Source Link

Document

Returns the 20 most recent tweets of the authenticated user that have been retweeted by others.

Usage

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

License:Apache License

/**
 *
 *///from   www .ja v a  2s  . c o  m
@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:Principal.Tracker_Twitter.java

License:Minecraft Mod Public

public void guardarResultados_Twitter(List<ObjetoBuscar> lista, BD base, int contadorBase, int TokenIndice)
        throws NoSuchAlgorithmException, KeyManagementException {
    int nuevoContadorBase = 0;
    if (contadorBase >= lista.size()) {
        System.out.println("Termino en:" + contadorBase);
    } else {/* www .  j a  v  a  2 s . c  om*/
        System.out.println("---------------------------------------------------------------------:P");

        TrustManager[] trustAllCerts = { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
        SSLContext sc = SSLContext.getInstance("SSL");

        sc.init(null, trustAllCerts, new SecureRandom());

        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

        System.out.println("Token : " + TokenIndice);
        System.out.println(consumerKey[TokenIndice]);
        try {
            ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setOAuthConsumerKey(consumerKey[TokenIndice]);
            cb.setOAuthConsumerSecret(this.consumerSecret[TokenIndice]);
            cb.setOAuthAccessToken(this.token[TokenIndice]);
            cb.setOAuthAccessTokenSecret(this.tokenSecret[TokenIndice]);
            Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance();

            for (int numtTweets = contadorBase; numtTweets < contadorBase + 5; numtTweets++) {

                if (((ObjetoBuscar) lista.get(numtTweets)).getUrl().equals("")
                        || ((ObjetoBuscar) lista.get(numtTweets)).getUrl() == null) {

                } else {

                    System.out.println("Usuario:  " + ((ObjetoBuscar) lista.get(numtTweets)).getUrl());

                    String usuariosinArroba = ((ObjetoBuscar) lista.get(numtTweets)).getUrl().replace("@", "");

                    System.out.println("" + usuariosinArroba);

                    try {

                        User usuario = unauthenticatedTwitter.showUser(usuariosinArroba);
                        List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe();
                        List<Status> favoritos = unauthenticatedTwitter.getFavorites();
                        Paging paging = new Paging(1, 1000);
                        ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(),
                                paging);
                        System.out.println("Followers: " + usuario.getFollowersCount());
                        System.out.println("Yo sigo: " + usuario.getFriendsCount());
                        List<String> listaTweets = new ArrayList();
                        List<Long> ListaRettewts = new ArrayList();
                        List<Integer> ListaFavoritos = new ArrayList();
                        List<Integer> ListaMenciones = new ArrayList();
                        List<Date> ListaFecha = new ArrayList();
                        List<Long> ListaIds = new ArrayList();
                        for (Status sta : statuses) {
                            ListaIds.add(Long.valueOf(sta.getId()));
                            listaTweets.add(sta.getText());
                            ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + "")));
                            ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length));
                            ListaFecha.add(sta.getCreatedAt());
                            ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount()));
                        }
                        for (int i = 0; i < listaTweets.size(); i++) {
                            base.guardarTrackTwitter_Log((Long) ListaIds.get(i),
                                    ((ObjetoBuscar) lista.get(numtTweets)).getUrl(),
                                    (String) listaTweets.get(i), (Date) ListaFecha.get(i),
                                    (Long) ListaRettewts.get(i), ((Integer) ListaFavoritos.get(i)).intValue(),
                                    ((Integer) ListaMenciones.get(i)).intValue());
                        }

                    } catch (Exception e) {
                        System.err.println("Entro al Try por :" + e);
                    }

                    nuevoContadorBase = numtTweets;
                }
            }
            System.out.println("Numero de Contador Base:" + nuevoContadorBase);
            guardarResultados_Twitter(lista, base, nuevoContadorBase + 1, TokenIndice + 1);
        } catch (NumberFormatException e) {
            System.err.println("Fallo por :" + e);
        }
    }
}