Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import tweepy
consumer_key = 'change with your consumer key'
consumer_secret = 'change with your consumer secret'
access_token = 'change with your access token'
access_secret = 'change with your access secret'
tweetsPerQry = 100
maxTweets = 1000000
hashtag = "#mencatatindonesia"
authentication = tweepy.OAuthHandler(consumer_key, consumer_secret)
authentication.set_access_token(access_token, access_secret)
api = tweepy.API(authentication, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
maxId = -1
tweetCount = 0
while tweetCount < maxTweets:
if(maxId <= 0):
newTweets = api.search(q=hashtag, count=tweetsPerQry, result_type="recent", tweet_mode="extended")
else:
newTweets = api.search(q=hashtag, count=tweetsPerQry, max_id=str(maxId - 1), result_type="recent", tweet_mode="extended")
if not newTweets:
print("Tweet Habis")
break
for tweet in newTweets:
print(tweet.full_text.encode('utf-8'))
tweetCount += len(newTweets)
maxId = newTweets[-1].id
@robtabamo9292
Copy link

robtabamo9292 commented Apr 23, 2021

Hi Dea,

Just wanted to reach out regarding your github project. Attempted to clone it because for informational and academic purposes. But ran into an error below. Was wondering if you would be open to help?

TweepError: [{'code': 89, 'message': 'Invalid or expired token.'}]

@YogeshGadade
Copy link

YogeshGadade commented Oct 27, 2021

Hi, robtabamo9292. Try to regenerate all keys, secrets, and tokens from your Twitter account and try again ... I faced the same error but it solved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment