Example usage for twitter4j IDs getIDs

List of usage examples for twitter4j IDs getIDs

Introduction

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

Prototype

long[] getIDs();

Source Link

Usage

From source file:twitterbot.TwitterActions.java

public void writeFriendsToDatabase() {
    try {/*w w  w  .  j ava2  s  . c o m*/
        IDs followerIDsCursor = twitter.getFollowersIDs(USER_NAME_BOT, lastStatusTime);
        long[] followerIDs = followerIDsCursor.getIDs();

        for (long id : followerIDs) {
            //write to database

        }
    } catch (TwitterException ex) {
        Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("Fetching followers failed!");
    }
}

From source file:TwitterDownload.TwitterHandler.java

public List<User> getUserFollowers(String searchPhrase, int pageSize) throws TwitterException {
    //todo test rate limit

    ArrayList<User> listFollowers = new ArrayList<User>();

    long cursor = -1;

    IDs followersIDs;

    do {//from w  w  w  .  j  ava  2 s  . c  om
        followersIDs = twitter.getFollowersIDs(searchPhrase, cursor);

        long[] ids = followersIDs.getIDs();

        while (ids.length > 0) {
            long[] searchIds = Arrays.copyOfRange(ids, 0, 100);
            if (ids.length >= 100)
                ids = Arrays.copyOfRange(ids, 100, ids.length);
            else
                ids = new long[0];

            ResponseList<User> users = twitter.lookupUsers(searchIds);

            for (User user : users) {
                listFollowers.add(user);
            }
        }

        if (followersIDs.hasNext())
            cursor = followersIDs.getNextCursor();
        else
            cursor = -1;
    } while (cursor > 0 && listFollowers.size() < pageSize);

    return listFollowers;
}

From source file:TwitterDownload.TwitterHandler.java

public List<User> getUserFriends(String searchPhrase, int pageSize) throws TwitterException {
    //todo test rate limit

    ArrayList<User> listFriends = new ArrayList<User>();

    long cursor = -1;

    IDs friendsIDs;

    do {/*w  w  w .  j  a va2s .co m*/
        friendsIDs = twitter.getFriendsIDs(searchPhrase, cursor);

        long[] ids = friendsIDs.getIDs();

        while (ids.length > 0) {
            long[] searchIds = Arrays.copyOfRange(ids, 0, 100);
            if (ids.length >= 100)
                ids = Arrays.copyOfRange(ids, 100, ids.length);
            else
                ids = new long[0];

            ResponseList<User> users = twitter.lookupUsers(searchIds);

            for (User user : users) {
                listFriends.add(user);
            }
        }

        if (friendsIDs.hasNext())
            cursor = friendsIDs.getNextCursor();
        else
            cursor = -1;
    } while (cursor > 0 && listFriends.size() < pageSize);

    return listFriends;
}

From source file:twitterlab.TwitterLab.java

/**
 * @param args the command line arguments
 *//* w  w w.jav a  2s .  com*/
public static void main(String[] args) {
    // TODO code application logic here
    Users = new ArrayList();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("yBSAPlE6wiAQU6CyIiXHSapwN");
    cb.setOAuthConsumerSecret("3CjbEkYyIZvNZ07KYpC55v9vpqxoNmMs1IkC48Wqr5tKXjUnZk");
    cb.setOAuthAccessToken("858371720-0RASIMJeaMbWr2YPmCPyh5OgCP6Kesgz0WvdsLz7");
    cb.setOAuthAccessTokenSecret("cfi5JDGLTUOKHNj7yFIdivg0Hr1bCml3VlQXj5XCOyoFr");

    try {
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter tw = tf.getInstance();
        IDs ids = tw.getFriendsIDs(-1);
        long[] ID;
        if (ids.getIDs().length > 10) {
            ID = new long[10];
            System.arraycopy(ids.getIDs(), 0, ID, 0, 10);
        } else {
            ID = ids.getIDs();
        }
        ResponseList<User> Friends = tw.lookupUsers(ID);
        User[] A = new User[10];
        if (Friends.toArray().length > 0) {
            Users.add(new ArrayList(Arrays.asList(Friends.toArray(A))));
        }
        for (int i = 0; i < ID.length; i++) {
            IDs idsFriend = tw.getFriendsIDs(ID[i], -1);
            long[] IDfriend;
            if (idsFriend.getIDs().length > 10) {
                IDfriend = new long[10];
                System.arraycopy(idsFriend.getIDs(), 0, IDfriend, 0, 10);
            } else {
                IDfriend = idsFriend.getIDs();
            }
            ResponseList<User> FriendsFriend = tw.lookupUsers(IDfriend);
            A = new User[10];
            if (FriendsFriend.toArray().length > 0) {
                Users.add(new ArrayList(Arrays.asList(FriendsFriend.toArray(A))));
            }
            //System.out.println("Sleep?");
            TimeUnit.SECONDS.sleep(60);
        }

        for (int i = 0; i < Users.size(); i++) {
            for (int j = 0; j < Users.get(0).size(); j++) {
                System.out.println(Users.get(i).get(j).getScreenName());
            }
        }

    } catch (Exception e) {
        // Thread.currentThread().interrupt();
        e.printStackTrace();
    }

}

From source file:twitterNetwork.Follower.java

public void getDetails(String id) throws Exception {
    ConfigurationBuilder cb1 = new ConfigurationBuilder();
    cb1.setOAuthConsumerKey(consumerKey1);
    cb1.setOAuthConsumerSecret(consumerSecret1);
    cb1.setOAuthAccessToken(twitterToken1);
    cb1.setOAuthAccessTokenSecret(twitterSecret1);
    ConfigurationBuilder cb2 = new ConfigurationBuilder();
    cb2.setOAuthConsumerKey(consumerKey2);
    cb2.setOAuthConsumerSecret(consumerSecret2);
    cb2.setOAuthAccessToken(twitterToken2);
    cb2.setOAuthAccessTokenSecret(twitterSecret2);
    ConfigurationBuilder cb3 = new ConfigurationBuilder();
    cb3.setOAuthConsumerKey(consumerKey3);
    cb3.setOAuthConsumerSecret(consumerSecret3);
    cb3.setOAuthAccessToken(twitterToken3);
    cb3.setOAuthAccessTokenSecret(twitterSecret3);

    Twitter twitter1 = new TwitterFactory(cb1.build()).getInstance();
    Twitter twitter2 = new TwitterFactory(cb2.build()).getInstance();
    Twitter twitter3 = new TwitterFactory(cb3.build()).getInstance();

    ConfigurationBuilder cb4 = new ConfigurationBuilder();
    cb4.setOAuthConsumerKey(consumerKey4);
    cb4.setOAuthConsumerSecret(consumerSecret4);
    cb4.setOAuthAccessToken(twitterToken4);
    cb4.setOAuthAccessTokenSecret(twitterSecret4);
    ConfigurationBuilder cb5 = new ConfigurationBuilder();
    cb5.setOAuthConsumerKey(consumerKey5);
    cb5.setOAuthConsumerSecret(consumerSecret5);
    cb5.setOAuthAccessToken(twitterToken5);
    cb5.setOAuthAccessTokenSecret(twitterSecret5);
    ConfigurationBuilder cb6 = new ConfigurationBuilder();
    cb6.setOAuthConsumerKey(consumerKey6);
    cb6.setOAuthConsumerSecret(consumerSecret6);
    cb6.setOAuthAccessToken(twitterToken6);
    cb6.setOAuthAccessTokenSecret(twitterSecret6);
    ConfigurationBuilder cb7 = new ConfigurationBuilder();
    cb7.setOAuthConsumerKey(consumerKey7);
    cb7.setOAuthConsumerSecret(consumerSecret7);
    cb7.setOAuthAccessToken(twitterToken7);
    cb7.setOAuthAccessTokenSecret(twitterSecret7);
    ConfigurationBuilder cb8 = new ConfigurationBuilder();
    cb8.setOAuthConsumerKey(consumerKey8);
    cb8.setOAuthConsumerSecret(consumerSecret8);
    cb8.setOAuthAccessToken(twitterToken8);
    cb8.setOAuthAccessTokenSecret(twitterSecret8);

    Twitter twitter4 = new TwitterFactory(cb4.build()).getInstance();
    Twitter twitter5 = new TwitterFactory(cb5.build()).getInstance();
    Twitter twitter6 = new TwitterFactory(cb6.build()).getInstance();

    Twitter twitter7 = new TwitterFactory(cb7.build()).getInstance();
    Twitter twitter8 = new TwitterFactory(cb8.build()).getInstance();
    setTname(id);/*from w  ww  .  j ava2s. co m*/
    String twittername = this.tname;
    System.out.println(twittername);

    //User u=twitter.showUser(usr);
    //PrintStream out=new PrintStream(new FileOutputStream("F:\\Projects\\Twitter_Network\\out.txt"));
    int w1 = 1, w2 = 1, w3 = 1, w4 = 1, w5 = 1, w6 = 1, w7 = 1, w8 = 1;
    //long id=u.getId();
    long lCursor = -1, nextCursor = -1;
    do {
        String twitterScreenName = twitter1.getScreenName();
        IDs followersIDs = twitter1.getFollowersIDs(twitterScreenName, -1);
        lCursor = nextCursor;
        //out.println("###"+nextCursor);

        //label:

        if (w1 != 16) {

            try {
                followersIDs = twitter1.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter1.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter1.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter1.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
                  out.println(k);
                          
               }*/
            nextCursor = followersIDs.getNextCursor();
            w1++;
        } else if (w2 != 16) {
            try {
                followersIDs = twitter2.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter2.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter2.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter2.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w2++;
        } else if (w3 != 16) {
            //IDs followerIDs = twitter3.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter3.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter3.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter3.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter3.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w3++;
        } else if (w4 != 16) {
            //IDs followerIDs = twitter4.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter4.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter4.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter4.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter4.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w4++;
        } else if (w5 != 16) {
            //IDs followerIDs = twitter5.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter5.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter5.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter5.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter5.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w5++;
        } else if (w6 != 16) {
            //IDs followerIDs = twitter6.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter6.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter6.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter6.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter6.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w6++;
        } else if (w7 != 16) {
            //IDs followerIDs = twitter7.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter7.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter7.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter7.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter7.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w7++;
        } else if (w8 != 16) {
            //IDs followerIDs = twitter8.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter8.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter8.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter8.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter8.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w8++;

            /*if(twitter8.getRateLimitStatus()!=null){
               if (twitter8.getRateLimitStatus().get("/users/lookup") != null){
               //   break label; 
               }
            }*/
        } else {
            try {
                TimeUnit.MINUTES.sleep(16);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            w1 = 1;
            w2 = 1;
            w3 = 1;
            w4 = 1;
            w5 = 1;
            w6 = 1;
            w7 = 1;
            w8 = 1;
        }

    } while (nextCursor != 0);

    //out.flush();
    //out.close();

}

From source file:twitterrest.Followersids.java

License:Apache License

static List<Long> followers(Twitter twitter, String screenName) {
    List<Long> m_FollowersList = new ArrayList<Long>();

    long cursor = -1;
    //int count = 0;
    while (true) {
        IDs ids = null;
        try {/*from w  w  w .  ja va2  s  . c  o m*/
            //IDs ids = twitter.getFollowersIDs(user.getId(), cursor);
            ids = twitter.getFollowersIDs(screenName, cursor);
        } catch (TwitterException twitterException) {
            // Rate Limit ?????????
            // () status code ?????????

            RateLimitStatus rateLimit = twitterException.getRateLimitStatus();
            int secondsUntilReset = rateLimit.getSecondsUntilReset();
            System.err.println("please wait for " + secondsUntilReset + " seconds");
            System.err.println("Reset Time : " + rateLimit.getResetTimeInSeconds());

            //() 120?getSecondsUntilReset() ????
            //?????????
            long waitTime = (long) (secondsUntilReset + 120) * 1000;
            //long waitTime = (long)(300 * 1000); // 300?
            try {
                Thread.sleep(waitTime);
            } catch (Exception e) {
                e.printStackTrace();
            }

            continue;
        } catch (Exception e) {
            e.printStackTrace();
        }

        long[] idArray = ids.getIDs();
        for (int i = 0; i < idArray.length; i++) {
            //System.out.println("["+(++count)+"]" + idArray[i]);
            m_FollowersList.add(new Long(idArray[i]));
        }

        if (ids.hasNext()) {
            cursor = ids.getNextCursor();
        } else {
            break;
        }
    }
    return m_FollowersList;
}

From source file:twittterbot08.TwittterBot08.java

public ArrayList<Long> getFollowerIDs(String screenName) throws TwitterException {
    ArrayList<Long> result = new ArrayList();
    long cursor = -1;
    IDs ids;
    do {//from  ww w  .j a  v a 2s  .  c o m
        ids = twitter.getFollowersIDs(screenName, cursor);
        for (long id : ids.getIDs()) {
            result.add(id);
        }
    } while ((cursor = ids.getNextCursor()) != 0);
    return result;
}

From source file:uniandes.cupi2.tweetSpy.mundo.TweeSpy.java

License:Academic Free License

/**
 * Retorna la lista de amigos del usuario.
 * @return//from w w  w .j  av a 2  s .c  o  m
 * @throws TwitterException
 */
public ListaDoblementeEncadenada<Usuario> darListaAmigos() throws TwitterException {
    listaAmigos = new ListaDoblementeEncadenada<Usuario>();
    User u1 = null;
    long cursor = -1;
    IDs ids;
    String resp = user.getScreenName();
    do {

        ids = user.getFriendsIDs(resp, cursor);
        for (long id : ids.getIDs()) {
            //System.out.println(id);
            User useri = user.showUser(id);
            String nombre = useri.getName();
            String name = useri.getScreenName();
            String url = useri.getOriginalProfileImageURL();
            String desc = useri.getDescription();
            //Para buscaar por indices
            ResponseList<Status> estatuses = user.getUserTimeline(name);

            Usuario nuevoAmigo = new Usuario(nombre, url, desc);
            nuevoAmigo.recibirTimeline(estatuses);
            listaAmigos.agregarFinal(nuevoAmigo);
            // contenedor?
        }
    } while ((cursor = ids.getNextCursor()) != 0);

    return listaAmigos;
}

From source file:uniandes.cupi2.tweetSpy.mundo.TweeSpy.java

License:Academic Free License

/**
 * Retorna la lista de seguidores del usuario.
 *///from w w w  .  j ava2 s. co m
public ListaDoblementeEncadenada<Usuario> darListaSeguidores() throws TwitterException {
    listaSeguidores = new ListaDoblementeEncadenada<Usuario>();
    User u1 = null;
    long cursor = -1;
    IDs ids;
    String resp = user.getScreenName();

    do {

        ids = user.getFollowersIDs(resp, cursor);
        for (long id : ids.getIDs()) {
            //System.out.println(id);
            User useri = user.showUser(id);
            String nombre = useri.getName();
            String url = useri.getOriginalProfileImageURL();
            String desc = useri.getDescription();
            Usuario nuevoAmigo = new Usuario(nombre, url, desc);
            listaSeguidores.agregarFinal(nuevoAmigo);
            // contenedor?
        }
    } while ((cursor = ids.getNextCursor()) != 0);

    return listaSeguidores;
}