Search code examples
twittertwitter-oauthtwitter4j

how do you get follower ID's of people who are not following you Twitter API


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);
    }
}

Solution

  • 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.