Reputation: 17
I'm trying to retrieve the most recent 3200 tweets from a user with the Tweepy v2 API. I authenticate fine and find the user with:
client = tweepy.Client(bearer_token=bearer_token,....
user = client.get_user(username=screen_name)
I can't seem to use a Cursor to get the tweets like this:
tweets = tweepy.Cursor(client.get_users_tweets,
id=user.data.id,
count=200).items(3200)
The error is "tweepy.errors.TweepyException: This method does not perform pagination". The Tweepy docs say that get_users_tweets does support pagination, though.
ETA traceback:
Traceback (most recent call last):
File "/Users/sean/projects/misc/./tweet-dump.py", line 71, in <module>
get_all_tweets("Daily_Epsilon")
File "/Users/sean/projects/misc/./tweet-dump.py", line 23, in get_all_tweets
tweets = tweepy.Cursor(client.get_users_tweets,
File "/usr/local/lib/python3.9/site-packages/tweepy/cursor.py", line 40, in __init__
raise TweepyException('This method does not perform pagination')
tweepy.errors.TweepyException: This method does not perform pagination
Upvotes: 1
Views: 1059
Reputation: 1843
The tweepy.Cursor
handles pagination for the Twitter API V1.1.
Since you are using Twitter API V2, you have to use a tweepy.Paginator
(see here).
So your code should be something like that:
# Please note that the count argument is called max_results in this method
paginator = tweepy.Paginator(client.get_users_tweets, id=user.data.id, max_results=200)
for tweet in paginator.flatten(limit=3200):
print(tweet)
Upvotes: 3