List_members limit?

29 views
Skip to first unread message

Alberto Alcaraz

unread,
Feb 22, 2015, 8:09:56 AM2/22/15
to twitter-...@googlegroups.com
Hello, 

I'm trying to get all the members of a list with the following code:

client.memberships(user["user"]).each do |list| 
   #some validation on each list
   client.list_members(list).each do |member|
      #do stuff

Everything seems to be ok, but when the script process a list with more that 4.000 members, it fails due to rate limits and get stuck. What I understood is that under the hood, there's a cursor to retrieve this lists automatically.

I don't know how to solve this. Ideally I'd like to process these big lists too, but I there's no other way, at list I would like to have a "count" on the members it has and skip if there are more than 4.000.

I hope somebody can give me a hand.

Thank you very much.

Alberto


Ian M

unread,
Mar 4, 2015, 1:12:55 PM3/4/15
to twitter-...@googlegroups.com
Hi Alberto,

I was just thinking the same.

I'm wondering if there's a 'user' related list method.
i.e. user.list_member_count("list_name")

Any progress for you?

Cheers,
Ian.

Ryan Williams

unread,
Mar 4, 2015, 7:41:59 PM3/4/15
to twitter-...@googlegroups.com
Couple of ideas.

1) member_count is available on the list:

client.memberships(user["user"]).each do |list|
   
#some validation on each list

   
next if list.member_count > X
   client
.list_members(list).each do |member|
     
#do stuff

2) use a higher count on the list_members call


client.memberships(user["user"]).each do |list|
   
#some validation on each list

   client
.list_members(list, { count: 5000, skip_status: true|false }).each do |member|
     
#do stuff

Where are you hitting rate limit? I'm guessing on the .memberships iterating?

There are also samples around on how to rescue the rate limit, sleep then resume again. I'll try to find some when more time.

Ryan Williams

unread,
Mar 4, 2015, 7:53:27 PM3/4/15
to twitter-...@googlegroups.com
Also, be sure to check the docs for all of the available parameters, and in case you didn't believe that you can get all 5000 list members in one call.  The default is 20, so you can imagine the rate limit savings of getting 5000 per call vs 20 per call.

https://dev.twitter.com/rest/reference/get/lists/members



On Sunday, February 22, 2015 at 5:09:56 AM UTC-8, Alberto Alcaraz wrote:
Reply all
Reply to author
Forward
0 new messages