Why am I getting “Too many terms specified in query” for calls within the Twitter API 100-user limitation?


I’m using https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all and https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all which both claim a limitation of 100 users per call. I limit my calls to 90 users, but I still intermittently receive a Too many terms specified in query error … I’ll even intermittently get this error when I limit my calls to 40 users or less.

It seems to apply only to certain users that I make the call on behalf of: I can iterate over some users just fine with my 90-user limit, but some of the users I iterate over will error out with Too many terms specified in query unless I severely limit my calls (for example, 10 users at a time) … but that severe limitation just presents a different problem - I hit Rate Limit when I try to make so many small calls for the user.

I’m iterating over each user in my database with User.all.each do |u|, and I’m creating a connection to Twitter for each user within that block with:

      client = Twitter::Client.new(
        :consumer_key => TWITTER_CONSUMER_KEY,
        :consumer_secret => TWITTER_CONSUMER_SECRET,
        :oauth_token => u.twitter_token,
        :oauth_token_secret => u.twitter_secret

This is the code I use to remove users from a list:

      removing_from_list.each_slice(90) do |remove_ids|
        client.list_remove_members(list_id, remove_ids)
        sleep 2

and this code to add users to a list:

      adding_to_list.each_slice(90) do |adding_ids|
        client.list_add_members(list_id, adding_ids)
        sleep 2

I’ve experienced this issue both in use of the Twitter gem as well as by accessing the Twitter API directly with Rested (a Mac REST client).


Are you checking what the membership levels of number of lists already owned by the user are at before adding additional members? Lists are currently limited to 500 members and 20 lists owned per user.


That must be the reason for the list_add_members errors - I just checked one of the problematic users, and see that their list is at 487 users.

This ‘500 members’ limitation on lists shouldn’t affect my list_remove_members calls, though (right?)… Any ideas on what could be causing my trouble with that call?

I’ve come across proper errors for the ‘20 lists owned per user’ limitation, so I don’t think that’s playing a part in my list_remove_members issue.


This appears to have been an issue with either the lists themselves, or the users who were present within the particular lists.

I changed my code so that it completely deletes the list, then recreates it, if this error occurs. I haven’t had this issue reappear since doing that, and I haven’t seen my code need to recreate the list more than once.


I’m encountering the same issue. Seems to be related to which user I try adding to my list. Can’t find any reasonable explanation in the API documentation.

My list currently has less than 500 members and trying to even just add 1 member throws this error.