Search code examples
pythontwittertweepy

how to return all tweets without providing a search query


I am working on a text mining project that deals with analyzing tweets.

I would like to get all tweets tweeted in english during a short period of time(not more than a day), without having the result matching to a specific search query, trend, or user criteria.

I am familiar with tweepy's api.search function. However, when i try to run it without a search query:

api.search(count=remaining_tweets, since_id=str(since_id),lang='en', max_id=str(max_id-1))

i get the following message: "exception raised, waiting 15 minutes".


Solution

  • You can get all the tweet by giving * to the query parameter:

    tweets = api.search(q='*', lang='en', count=200, since_id=since_id, max_id=max_id)
    

    If you need a specific number of tweets, you could use tweepy Cursor like this:

    # Get 1000 English tweets from max_id
    tweets = [tweet for tweet in tweepy.Cursor(
        api.search, q='*', lang='en', count=200, max_id=max_id).items(1000)]