Hi,

I’m using search-tweets-python to retrieve all tweets of a given user for particular time, however, seems the max_results =100, what if the users had more tweets in that period?

And how the price of this is calculated? lets say the user had 10k tweets in that period?

tweets = collect_results(rule,
                         max_results=100,
                         result_stream_args=premium_search_args)

Premium counts and charges for calls to the API - so for 1 successful call, no matter how many results it returns, 1 call is “charged” to your account.

1 call can return a max of 100 tweets in the sandbox level (or 500 in any paid level), from a maximum of a 30 day period. For example: It would take 2 calls to retrieve 200 tweets in a 30 day period, and it will also take 2 calls to retrieve 100 tweets spread over a 60 day period.

In ideal circumstances, it would take 100 calls in sandbox to get 10,000 tweets, but in practice it’s going to be more because of this 30 day limitation.

You have to use the next token in your calls to retrieve the next “page” of results, but search-tweets-python does this for you: Have a look at https://github.com/twitterdev/search-tweets-python#working-with-the-resultstream but note that there are two ways of specifying a stopping condition: number of tweets (max_results) and number of calls (max_pages).

2 Likes

Thank you! so what is the difference between ‘collect_results’ and ‘ResultStream’ ? one has max_pages and the other doesn’t? Thanks!

collect_results is a wrapper around ResultStream - it calls ResultStream and returns a list of tweets. This will matter once the result set gets larger - you want to use ResultStream generator and stream results in rather than loading everything into a list in memory.

write_result_stream function is a good one to use to write tweets as they get retrieved https://github.com/twitterdev/search-tweets-python/blob/master/searchtweets/utils.py#L100

All that is already implemented in the CLI https://github.com/twitterdev/search-tweets-python#using-the-comand-line-application

(I’d use --max-pages to limit things as it’s easier to predict rather than number of tweets)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.