9

Twitter allows up to 100 user ids at a time to query for user profile information. But if there is an invalid ID among those, it returns:

404 (Not Found), No user matches for specified terms

without specifying which is the bad ID and no data is returned for the rest of the users in the list. This happens if a user in the list closes their account.

Is there a way to identify the invalid ID without going through the list once again one by one (and possibly hitting the rate limit)?

onurmatik
  • 5,105
  • 7
  • 42
  • 67

2 Answers2

2

https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup.html

  • If a requested user is unknown, suspended, or deleted, then that user will not be returned in the results list.
  • If none of your lookup criteria can be satisfied by returning a user object, a HTTP 404 will be thrown.

From my understanding this means:

  • If you request 10 userIds and 1 of them is suspended, the request should still return 9 results
  • If you request 2 userIds and all of them are suspended, the request will return that error

I did a quick test and it seems to work as described. Could it be that all of the IDs in your request are invalid?

patrickd
  • 186
  • 1
  • 12
-1

You can use puts command for printing user id on first loop and you can see your log file or console to get the user id which is invalid.

Hitesh Ranaut
  • 751
  • 6
  • 12
  • thanks, but what do you mean by "first loop"? do you suggest first checking the users one by one? i want to avoid hitting twitter once for each user in the list, as i've stated in the question. – onurmatik Dec 04 '15 at 08:02
  • If you want to just skip the invalid user and go on with the valid you can work on exception handling. – Hitesh Ranaut Dec 04 '15 at 08:42
  • using exception handling you will be able to skip the id with error and code with not stop. if and user id is invalid – Hitesh Ranaut Dec 04 '15 at 08:44
  • ok, sure, but i'm fetching 100 user at once, i.e. with a single query. this is the twitter limit. i am not doing it one by one. and if a user fails in that batch of 100, it does not tell which one. – onurmatik Dec 04 '15 at 15:18
  • okay which language you are using ? can you paste your code here? – Hitesh Ranaut Dec 07 '15 at 08:58