Example usage for twitter4j Twitter getFollowersIDs

List of usage examples for twitter4j Twitter getFollowersIDs

Introduction

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

Prototype

IDs getFollowersIDs(long userId, long cursor) throws TwitterException;

Source Link

Document

Returns an array of numeric IDs for every user the specified user is followed by.

Usage

From source file:org.loklak.harvester.TwitterAPI.java

License:Open Source License

public static JSONObject getNetworkerNames(final String screen_name, final int max_count,
        final Networker networkRelation) throws IOException, TwitterException {
    if (max_count == 0)
        return new JSONObject();
    boolean complete = true;
    Set<Number> networkingIDs = new LinkedHashSet<>();
    Set<Number> unnetworkingIDs = new LinkedHashSet<>();
    JsonFactory mapcapsule = (networkRelation == Networker.FOLLOWERS ? DAO.followers_dump : DAO.following_dump)
            .get("screen_name", screen_name);
    if (mapcapsule == null) {
        JsonDataset ds = networkRelation == Networker.FOLLOWERS ? DAO.followers_dump : DAO.following_dump;
        mapcapsule = ds.get("screen_name", screen_name);
    }//from  w ww  .  jav  a2  s . com

    if (mapcapsule != null) {
        JSONObject json = mapcapsule.getJSON();

        // check date and completeness
        complete = json.has("complete") ? (Boolean) json.get("complete") : Boolean.FALSE;
        String retrieval_date_string = json.has("retrieval_date") ? (String) json.get("retrieval_date") : null;
        DateTime retrieval_date = retrieval_date_string == null ? null
                : AbstractObjectEntry.utcFormatter.parseDateTime(retrieval_date_string);
        if (complete && System.currentTimeMillis() - retrieval_date.getMillis() < DateParser.DAY_MILLIS)
            return json;

        // load networking ids for incomplete retrievals (untested)
        String nr = networkRelation == Networker.FOLLOWERS ? "follower" : "following";
        if (json.has(nr)) {
            JSONArray fro = json.getJSONArray(nr);
            for (Object f : fro)
                networkingIDs.add((Number) f);
        }
    }
    TwitterFactory tf = getUserTwitterFactory(screen_name);
    if (tf == null)
        tf = getAppTwitterFactory();
    if (tf == null)
        return new JSONObject();
    Twitter twitter = tf.getInstance();
    long cursor = -1;
    collect: while (cursor != 0) {
        try {
            IDs ids = networkRelation == Networker.FOLLOWERS ? twitter.getFollowersIDs(screen_name, cursor)
                    : twitter.getFriendsIDs(screen_name, cursor);
            RateLimitStatus rateStatus = ids.getRateLimitStatus();
            if (networkRelation == Networker.FOLLOWERS) {
                getFollowerIdRemaining = rateStatus.getRemaining();
                getFollowerIdResetTime = System.currentTimeMillis() + rateStatus.getSecondsUntilReset() * 1000;
            } else {
                getFollowingIdRemaining = rateStatus.getRemaining();
                getFollowingIdResetTime = System.currentTimeMillis() + rateStatus.getSecondsUntilReset() * 1000;
            }
            //System.out.println("got: " + ids.getIDs().length + " ids");
            //System.out.println("Rate Status: " + rateStatus.toString() + "; time=" + System.currentTimeMillis());
            boolean dd = false;
            for (long id : ids.getIDs()) {
                if (networkingIDs.contains(id))
                    dd = true; // don't break loop here
                networkingIDs.add(id);
            }
            if (dd)
                break collect; // this is complete!
            if (rateStatus.getRemaining() == 0) {
                complete = false;
                break collect;
            }
            if (networkingIDs.size() >= Math.min(10000, max_count >= 0 ? max_count : 10000)) {
                complete = false;
                break collect;
            }
            cursor = ids.getNextCursor();
        } catch (TwitterException e) {
            complete = false;
            break collect;
        }
    }
    // create result
    JSONObject json = new JSONObject(true);
    json.put("screen_name", screen_name);
    json.put("retrieval_date", AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis()));
    json.put("complete", complete);
    Map<String, Number> networking = getScreenName(networkingIDs, max_count, true);
    Map<String, Number> unnetworking = getScreenName(unnetworkingIDs, max_count, true);
    if (networkRelation == Networker.FOLLOWERS) {
        json.put("followers_count", networking.size());
        json.put("unfollowers_count", unnetworking.size());
        json.put("followers_names", networking);
        json.put("unfollowers_names", unnetworking);
        if (complete)
            DAO.followers_dump.putUnique(json); // currently we write only complete data sets. In the future the update of datasets shall be supported
    } else {
        json.put("following_count", networking.size());
        json.put("unfollowing_count", unnetworking.size());
        json.put("following_names", networking);
        json.put("unfollowing_names", unnetworking);
        if (complete)
            DAO.following_dump.putUnique(json);
    }
    return json;
}

From source file:org.thiesen.startpath.data.TwitterExporter.java

License:Open Source License

private static void findForUser(final PrintWriter outputStreamWriter, final long id, final Set<Long> seen)
        throws TwitterException {
    final Twitter twitter = new TwitterFactory().getInstance();
    final IDs followersIDs = twitter.getFollowersIDs(id, -1);
    printTarget(outputStreamWriter, followersIDs, id);
    final IDs friendsIDs = twitter.getFriendsIDs(id, -1);
    printSource(outputStreamWriter, id, friendsIDs);

    recurse(outputStreamWriter, seen, followersIDs);
    recurse(outputStreamWriter, seen, friendsIDs);
}

From source file:org.wso2.carbon.connector.twitter.TwitterGetFollowersIds.java

License:Open Source License

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    if (log.isDebugEnabled()) {
        log.info("executing twitter get user time line");
    }/*w w  w . j a v  a  2 s.  c o  m*/

    try {

        String screenName = (TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME).isEmpty())

                        ? TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME)
                        : null;

        String userID = (TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, USER_ID).isEmpty())

                        ? TwitterUtils.lookupTemplateParamater(messageContext, USER_ID)
                        : null;

        String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT)
                        : null;

        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();

        IDs ids = null;

        if (screenName != null && !screenName.isEmpty()) {
            if (count != null && !count.isEmpty()) {
                ids = twitter.getFollowersIDs(screenName, Long.parseLong(count));
            } else {
                ids = twitter.getFollowersIDs(screenName, -1);
            }
        } else if (userID != null && !userID.isEmpty()) {
            if (count != null && !count.isEmpty()) {
                ids = twitter.getFollowersIDs(Long.parseLong(userID), Long.parseLong(count));
            } else {
                ids = twitter.getFollowersIDs(Long.parseLong(userID), -1);
            }
        }

        if (log.isDebugEnabled()) {
            log.error("Retrived result: " + ids.toString());
        }

        OMElement element = this.performSearchMessages(ids.getIDs());

        super.preparePayload(messageContext, element);

    } catch (TwitterException te) {
        log.error("Failed to search twitter : " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    } catch (Exception te) {
        log.error("Failed to search generic: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }
}

From source file:peoplesearch.FindFriendsAndFollowers.java

public void GetFollowersIDs() {
    try {/*  w  w  w.ja va2  s.com*/
        // I need to pass the Person name and the TwitterID.
        //String targetname="Philip Bergkvist";
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;

        ResponseList<User> users1 = null;
        ResponseList<User> users2 = null;
        System.out.println("Listing followers's ids.");

        GraphManager mgr = EmbeddedGraphManager.getInstance();

        mgr.init(new File("/usr/local/Cellar/neo4j/2.1.7/libexec/data/forlang1.db"));
        //mgr.addTwitterAccount(new TwitterAccountImpl(new Date(), "I am Studying", 13, 82, true,"Aalborg", "Philiptwoshoes", 2730631792L));
        List<TwitterAccount> twitteraccountslist;
        twitteraccountslist = null;
        twitteraccountslist = mgr.listTwitterAccounts();
        System.out.println("the number of twitter account in the neo4J DB is" + twitteraccountslist.size());
        for (TwitterAccount Twit : twitteraccountslist) {

            do {
                TwitterLimitWait tlw = new TwitterLimitWait();
                tlw.CheckLimit();

                if (0 < twitteraccountslist.size()) {
                    ids = twitter.getFollowersIDs(Twit.getScreenName(), cursor); //.getFollowersIDs(pep[0], cursor);
                    //ids = twitter.getFollowersIDs("Philiptwoshoes", cursor); //.getFollowersIDs(pep[0], cursor);
                    tlw.CheckLimit();
                    users1 = twitter.getFollowersList(Twit.getScreenName(), cursor);
                    tlw.CheckLimit();
                    users2 = twitter.getFriendsList(Twit.getScreenName(), cursor);

                } else {
                    tlw.CheckLimit();
                    ids = twitter.getFollowersIDs(cursor);

                }

                for (User user : users1) {
                    tlw.CheckLimit();
                    System.out.println("the follower called " + user.getName() + " with twitter handler "
                            + user.getScreenName());
                    String username = user.getName();
                    //mgr.addPerson(new PersonImpl(username));
                    Date Creation = user.getCreatedAt();
                    tlw.CheckLimit();
                    String descript = user.getDescription();
                    boolean empty1 = user.getDescription().isEmpty();
                    if (empty1 == true) {
                        descript = " ";
                    }
                    tlw.CheckLimit();
                    int followers = user.getFollowersCount();
                    tlw.CheckLimit();
                    int following = user.getFriendsCount();
                    boolean geo = user.isGeoEnabled();
                    String loc = user.getLocation();
                    boolean empty2 = user.getLocation().isEmpty();
                    if (empty2 == true) {
                        loc = " ";
                    }
                    String screenname = user.getScreenName();
                    boolean empty3 = user.getScreenName().isEmpty();
                    if (empty3 == true) {
                        screenname = " ";
                    }
                    tlw.CheckLimit();
                    long twitID = user.getId();

                    mgr.linkPersonToTwitterAccount(new PersonImpl(username), new TwitterAccountImpl(Creation,
                            descript, followers, following, geo, loc, screenname, twitID));
                    mgr.linkTwitterAccounts(new TwitterAccountImpl(Creation, descript, followers, following,
                            geo, loc, screenname, twitID), Twit);
                }

                System.out.println("The total number of followers is: " + users1.size());
                // the same procedure for the Following
                for (User user : users2) {
                    tlw.CheckLimit();
                    System.out.println("the following called " + user.getName() + " with twitter handler "
                            + user.getScreenName());
                    String username1 = user.getName();
                    //mgr.addPerson(new PersonImpl(username1));
                    Date Creation = user.getCreatedAt();
                    String descript = user.getDescription();
                    boolean empty1 = user.getDescription().isEmpty();
                    if (empty1 == true) {
                        descript = " ";
                    }
                    int followers = user.getFollowersCount();
                    int following = user.getFriendsCount();
                    boolean geo = user.isGeoEnabled();
                    String loc = user.getLocation();
                    boolean empty2 = user.getLocation().isEmpty();
                    if (empty2 == true) {
                        loc = " ";
                    }
                    String screenname = user.getScreenName();
                    tlw.CheckLimit();
                    boolean empty3 = user.getScreenName().isEmpty();
                    if (empty3 == true) {
                        screenname = " ";
                    }
                    tlw.CheckLimit();
                    long twitID = user.getId();
                    //mgr.addTwitterAccount(new TwitterAccountImpl(Creation,descript,followers,following,geo,loc,screenname,twitID));
                    mgr.linkPersonToTwitterAccount(new PersonImpl(username1), new TwitterAccountImpl(Creation,
                            descript, followers, following, geo, loc, screenname, twitID));
                    mgr.linkTwitterAccounts(Twit, new TwitterAccountImpl(Creation, descript, followers,
                            following, geo, loc, screenname, twitID));
                }
                System.out.println("The total number of friend is: " + users2.size());

                //}
            } while ((cursor = ids.getNextCursor()) != 0);

        }
        mgr.destroy(); // I have to check that the second iteration works fine, because i could not test that.
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get followers' ids: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitfeedbot.BotherSomeoneServlet.java

License:Open Source License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Twitter twit;
    StringBuilder builder = new StringBuilder();
    User victim = null;//from ww  w . ja va2 s  .c o  m
    long cursor = -1;
    long[] friendIDs, victimIDs;
    Random r = new Random();

    resp.setContentType("text/html");
    resp.getWriter().println("<html>");
    resp.getWriter().println("<body>");
    try {
        ConfigurationBuilder twitterConfigBuilder = new ConfigurationBuilder();
        twitterConfigBuilder.setDebugEnabled(false);

        System.setProperty("WORDNIK_API_KEY", WORDNIK_KEY);
        twitterConfigBuilder.setOAuthConsumerKey(CONSUMER_KEY);
        twitterConfigBuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
        twitterConfigBuilder.setOAuthAccessToken(ACCESS_TOKEN);
        twitterConfigBuilder.setOAuthAccessTokenSecret(ACCESS_SECRET);

        twit = new TwitterFactory(twitterConfigBuilder.build()).getInstance();

        Trends t = twit.getPlaceTrends(1); //global trends
        friendIDs = twit.getFollowersIDs(twit.getId(), cursor).getIDs();
        if (friendIDs.length == 0)
            resp.getWriter().println("Cannot find any followers to bother");
        else {
            victimIDs = twit.getFollowersIDs(friendIDs[r.nextInt(friendIDs.length)], cursor).getIDs();
            if (victimIDs.length == 0)
                resp.getWriter().println("Cannot find any followers to bother");
            else {
                victim = twit.showUser(victimIDs[r.nextInt(victimIDs.length)]);
                builder.append("@" + victim.getScreenName()).append(" ");
                //Append Wordnik example sentence
                builder.append(WordApi.topExample(WordsApi.randomWord().getWord()).getText());
                if (builder.length() > 140) //Tweets are maximum 140 characters
                {
                    if (builder.lastIndexOf(";", 110) > 0)
                        builder.setLength(builder.lastIndexOf(";", 110));
                    else if (builder.lastIndexOf(":", 110) > 0)
                        builder.setLength(builder.lastIndexOf(":", 110));
                    else if (builder.lastIndexOf(",", 110) > 0)
                        builder.setLength(builder.lastIndexOf(",", 110));
                    else
                        builder.setLength(110);
                }
                builder.append(" " + t.getTrends()[r.nextInt(t.getTrends().length)].getName());

                if (builder.length() > 140)
                    builder.setLength(140); //Tweets are limited to 140 characters

                twit.updateStatus(builder.toString());
                resp.getWriter().println("Tweet posted: " + builder.toString() + "<br>");
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("Input file(s) not found<br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter <br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (KnickerException e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("Problem with Wordnik <br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (Exception e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    }
}

From source file:twitter4j.examples.friendsandfollowers.GetFollowersIDs.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendsandfollowers.GetFollowersIDs [screen name]
 *
 * @param args message/*  w  w w . ja v a 2  s .c o m*/
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Listing followers's ids.");
        do {
            if (0 < args.length) {
                ids = twitter.getFollowersIDs(args[0], cursor);
            } else {
                ids = twitter.getFollowersIDs(cursor);
            }
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get followers' ids: " + te.getMessage());
        System.exit(-1);
    }
}

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);//w  w  w. j a  va 2s . c om
    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;/*from w  w  w.  java 2s  . c  om*/
        try {
            //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;
}