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

myfollowerlist
@myfollowerlist MyFollowerList

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:

  1.       client = Twitter::Client.new(
  2.         :consumer_key => TWITTER_CONSUMER_KEY,
  3.         :consumer_secret => TWITTER_CONSUMER_SECRET,
  4.         :oauth_token => u.twitter_token,
  5.         :oauth_token_secret => u.twitter_secret
  6.       )

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

  1.       removing_from_list.each_slice(90) do |remove_ids|
  2.         client.list_remove_members(list_id, remove_ids)
  3.         sleep 2
  4.       end

and this code to add users to a list:

  1.       adding_to_list.each_slice(90) do |adding_ids|
  2.         client.list_add_members(list_id, adding_ids)
  3.         sleep 2
  4.       end

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

1 year 13 weeks ago

Replies

episod
@episod Taylor Singletary

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.

1 year 13 weeks ago
myfollowerlist
@myfollowerlist MyFollowerList

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.

1 year 13 weeks ago
myfollowerlist
@myfollowerlist MyFollowerList

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.

1 year 12 weeks ago
marckohlbrugge
@marckohlbrugge Marc Köhlbrugge

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.

48 weeks 5 days ago