0
votes

I am trying to get all the followersIDs from an a twitter account with about 150.000 followers. I later want to map their location, but first I need all those IDs.

at the moment I am using this code:

long lCursorIDs = -1;
    long[] fArray = new long[100];

    do
    {               
        fArray = twitter.getFollowersIDs(name, lCursorIDs).getIDs();            
    } while (twitter.getFollowersIDs(name, lCursorIDs).hasNext ()); 

    try
    {
        PrintWriter pr = new PrintWriter(filenameOutput);    

        for (int i=0; i<fArray.length ; i++)
        {
            pr.println(fArray[i]);
        }
        pr.close();
        System.out.println("Follower IDs collected and saved to file: " + filenameOutput );
    }
    catch (Exception e)
    {
        e.printStackTrace();
        System.out.println("No such file exists.");
    }

This works for User with less followers. but with that many it always returns an error message - rate limit exceeded. I was thinking about getting only a certain number of followersIDs per hour, but I am not sure how to do that and not start every hour from the beginning with the first follower. also, I am not sure how many followers I can get with one request. maybe it is 100, as with the "lookupUser" method but I am not sure.. any ideas/suggestions?

EDIT: ok, I just tried to get the followerIDs of an account with 2700 followers and it stored them correctly in the text file. It also only "cost" one request. than I changed the account name to an account with 15500 followers and it crashes again with an rate limit exceeded message. I don´t get why since it´s only roughly 6 times as many followers but all the remaining requests get spend.. any ideas on what I´m doing wrong?

1

1 Answers

1
votes

the answer:

 int numberOfFollowers; 
    numberOfFollowers = user.getFollowersCount(); 

            //CREATE ARRAYS FOR FOLLOWER IDS
    long cursor = -1;
    long[] fArray = new long[numberOfFollowers];
    long[] local = new long[5000];


    IDs ids = twitter.getFollowersIDs(name, cursor);
    int j = 0;

            int x = 5000;
    int durchgang = 1;
    int d_anzahl = 1 + numberOfFollowers / 5000;
    //STROE FOLLOWER IDS IN ARRAYS
    do 
    {                       
        ids = twitter.getFollowersIDs(name, cursor);            
        local = twitter.getFollowersIDs(name, cursor).getIDs();
        System.out.println("Durchgang: " + durchgang + " / " + d_anzahl );          
        System.arraycopy(local, 0, fArray, j * x , local.length);           
        j++;
        durchgang++;

        cursor = ids.getNextCursor();           
    } while (ids.hasNext());

this gets an array with all follower IDs of any twitter User. It calculates the number of loops needed to get all follower IDs and copys each array of 5000 IDs into new array which has all IDs at the end.