Using LookUpUsers Combined With Error Handling


Hello everyone,

I am working on a research project at the moment where I have about 210 or so tweets in my possession from six months ago. I am trying to retrieve all the real names from the users (I already have their screen names). The problem is that certain screen names that were valid six months ago appear to be invalid at this point in time and will return a 404 error. I have a TwitterException that catches this and then skips that user’s screen name in the list and continues on with my loop. This works perfectly except I am using the Twitter API for every individual call which I have found out I don’t want because of the RateLimit issues.

Now if I use the lookUpUsers method and put all of the results in a list I would be calling the API in only 2 calls or so right? If this is more efficient I want to do this but I don’t know how to go about error handling then. When I was handling tweets individually if I got a 404 error from one of them I could just handle it with an exception and use the keyword “continue” to keep going with my loop. But with this list of 100 screen names in an array per call I don’t know how to do that.

In addition, if I were to give lookUpUsers a number below 100 it would still work fine right?

Any suggestions or help would be greatly appreciated! I am also using Twitter4J…


It’s definitely more efficient to use users/lookup. You can send up to 100 criteria at a time, but you can specify as little as you like. You’ll be rate limited per request in either case.

If there are no matches to any of the criteria you’ve presented, you’ll get a HTTP 404 on users/lookup. If one or more results match your criteria, you’ll get them back in the response. Compare the user objects and their screen_names that you get in response to the list of screen names you queried with – the screen names that are missing are the users that would have 404’d for you on users/show.