Question

I have a list of tweets with information about the user who tweeted them that I am using for an undergrad research project. To build a social network graph of these tweets I need to grab their friend and follower lists. I have tried using the GET Follower IDs call through the twitter4j platform. My authentication is Oauth with Read, write, and direct messages. I get a 400 response code with no further error code. I also get the following exception code

exceptionCode=[92c30ec6-19bed99c 70a5018f-1e1c55ac 70a5018f-1e1c55aa], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3}

This tells me that I'm not authenticated to make this request which from what I have read is because the people are not followers of mine. Is there a way I can request this information without having this relationship with the user?

here is my code

public static void main (String[] args){
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
    .setOAuthConsumerKey("something")
    .setOAuthConsumerSecret("something else")
    .setOAuthAccessToken("another thing")
    .setOAuthAccessTokenSecret("a secret thing")
    .setUseSSL(true)
    .setUserStreamRepliesAllEnabled(true);
    Twitter twitter = new TwitterFactory(cb.build()).getInstance();
    long cursor = -1;
    IDs ids = null;
    String[] users = new String[16717];

    BufferedReader br = null;
    try {//getting user screen names
        String sCurrentLine;
        br = new BufferedReader(new FileReader("users.txt"));
        int i = 0;
        while ((sCurrentLine = br.readLine()) != null) {
            users[i]=sCurrentLine;
            i++;
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    for(int i=0;i<users.length;i++){
        System.out.println("==================="+users[i]+"===================");
        do {
            try {
                ids = twitter.getFollowersIDs(users[i], cursor);
                for (long id : ids.getIDs()) {
                    System.out.println(id);
                    User user = twitter.showUser(id);
                    System.out.println(user.getName());
                }
            } catch (TwitterException e) {
                e.printStackTrace();
            }
        } while ((cursor = ids.getNextCursor()) != 0);
    }
}
Was it helpful?

Solution 2

In an extremely embarrassing turn of events it turns out that the reason the request could not be made is that the usernames I was searching with had an extra space. So I trimmed each name and it works now.

OTHER TIPS

One can obtain the list of followers IDs for any public twitter user using this API from twitter. I don't use twitter4j but it should work fine.

Main thing to be conscious of, outside of authentication, is that twitter allows fetching maximum 5000 IDs in one call and rate limits aggressively (15 calls per app/user token) so your application has to be designed and built to honor those considerations/limitations with appropriate tokens/sleeps etc. For e.g. if you use the application token and a given user has 100K followers, twitter will start returning rate_limit_exceeded errors after fetching 75K (5K * 15) followers IDs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top