Last active
December 22, 2022 13:22
-
-
Save mGalarnyk/5b251ea41c3626d6965ac7d5006da432 to your computer and use it in GitHub Desktop.
Get more than 100 Tweets at a time using paginator. If you need more than 100 Tweets, you will have to use paginator (https://docs.tweepy.org/en/latest/pagination.html). Replace the limit=1000 with the maximum number of tweets you want.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OAuth2.0 Version | |
import tweepy | |
#Put your Bearer Token in the parenthesis below | |
client = tweepy.Client(bearer_token='Change this') | |
""" | |
If you don't understand search queries, there is an excellent introduction to it here: | |
https://github.com/twitterdev/getting-started-with-the-twitter-api-v2-for-academic-research/blob/main/modules/5-how-to-write-search-queries.md | |
""" | |
# Get tweets that contain the hashtag #petday | |
# -is:retweet means I don't wantretweets | |
# lang:en is asking for the tweets to be in english | |
query = '#petday -is:retweet lang:en' | |
tweets = tweepy.Paginator(client.search_recent_tweets, query=query, | |
tweet_fields=['context_annotations', 'created_at'], max_results=100).flatten(limit=1000) | |
for tweet in tweets: | |
print(tweet.text) | |
if len(tweet.context_annotations) > 0: | |
print(tweet.context_annotations) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OAuth2.0 Version
import tweepy
#Put your Bearer Token in the parenthesis below
client = tweepy.Client(bearer_token='Change this')
"""
If you don't understand search queries, there is an excellent introduction to it here:
https://github.com/twitterdev/getting-started-with-the-twitter-api-v2-for-academic-research/blob/main/modules/5-how-to-write-search-queries.md
"""
Get tweets that contain the hashtag #petday
-is:retweet means I don't wantretweets
lang:en is asking for the tweets to be in english
query = '#petday -is:retweet lang:en'
tweets = tweepy.Paginator(client.search_recent_tweets, query=query,
tweet_fields=['context_annotations', 'created_at'], max_results=100).flatten(limit=1000)
for tweet in tweets:
print(tweet.text)
if len(tweet.context_annotations) > 0:
print(tweet.context_annotations)