Reputation: 45
I want to get at least 10,000 of the most recent tweets containing the word 'bitcoin' using tweepy. I checked the parameters, and people online are saying the number of tweets (count) that tweepy's api.search_tweets() can be up to 18,000... but when i use 10,000 as the count it only returns a list of the 100 most recent tweets. I attached some code below to check out. Lemme know if anyone knows an answer to this.
# setting my query
search_term = "bitcoin -filter:retweets"
# making a list of all tweets with my query
search_tweets = api.search_tweets(q = search_term, lang = "en", count = 10000)
# shows me how many tweets api.search_tweets() gets
print(f"Number of tweets found: {len(search_tweets)}")
# loops through each tweet in search_tweets and prints information about each tweet
for tweet in search_tweets:
print(f"{tweet.user.name} tweeted: ")
print(tweet.text)
print(f"# of likes: {tweet.favorite_count}")
print(f'# of retweets: {tweet.retweet_count}')
print("-------------------------------------------------------------------------------") #seperates each tweet
this outputs this: https://i.sstatic.net/BHQuV.png
You can see it works, but we still only get a list of 100 tweets when my count is 18,000...
Upvotes: 0
Views: 1414
Reputation: 95
Use tweepy's cursor object get more than 100 tweets.
Here's an example:
n=500
tweets=tweepy.Cursor(api.search_tweets,q="#bitcoin",lang="en",tweet_mode="extended").items(n)
tweets_json=[]
for tweet in tweets:
tweets_json.append(tweet._json)
This will return a list which contains the tweet info in json format.
Upvotes: 1
Reputation: 54698
Did you check the documentation? That request is limited to 100 at a time.
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets
count optional The number of tweets to return per page, up to a maximum of 100. Defaults to 15. This was formerly the "rpp" parameter in the old Search API. 100
Upvotes: 0