smitty_werben_jagerm
smitty_werben_jagerm

Reputation: 394

Tweepy search_users returns only 50 records

I am looking to search twitter for all users with a keyword in their user name. I am doing this by:

api = tweepy.API(auth, wait_on_rate_limit= True)

def get_users():
count = 0
all_users = []
for page in tweepy.Cursor(api.search_users,["keyword"]).pages():
    #page[0] has the UserObj
    id_str = page[0].id_str
    scr_name = page[0].screen_name
    print(count, id_str)

This is working, but it is only returning the first 50 results. How do I return a larger set of results? Say upwards of 2000?

Upvotes: 0

Views: 251

Answers (1)

Mickaël Martinez
Mickaël Martinez

Reputation: 1843

First of all, you can retrieve only the first 1000 users with the API (see here).

Then, why are you only using the page[0] ? There are 20 users par page, not only one. My bet would be that this is why you have this problem (you can get only 1000 users, so that means 50 pages if you get 20 users per page, so 50 users if you read only the first user of each page).

By the way, you could use .items() instead of .pages().

Upvotes: 2

Related Questions