Search code examples
pythontwittertweepy

Query Twitter profiles created within a date range?


I'm currently using Tweepy to get a set of user profiles that contain certain words like this:

profile_query = "cats, dogs"
profiles = api.search_users(profile_query)

for profile in profiles:
    print(profile.screen_name)
    print(profile.description)

Is there a way to query profiles that were created within a certain date range? The only way I can think to do it is to use a Cursor query, but this seems to ignore the dates I set:

date_since = "2021-04-01"
profiles = tweepy.Cursor(api.search_users,
                         q=profile_query,
                         lang="en",
                         since=date_since).items(5)

The above query still returns profiles that were created before 2021-04-01. Is there a way to query profiles that were created on/after a specific date?

Thanks!


Solution

  • No, there is no Twitter API for this. The Cursor is only going to be useful for paging through the results, but the search_users method itself does not support a since parameter, so this will be ignored - which is what you are seeing. You would have to manually filter out profiles by date in your code, and "drop" the profiles whose creation date is outside of your required range.