Skip to content

Instantly share code, notes, and snippets.

@DeaVenditama
Last active February 5, 2023 03:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save DeaVenditama/40ed30cb4bc793ab1764fc3105258d8a to your computer and use it in GitHub Desktop.
Save DeaVenditama/40ed30cb4bc793ab1764fc3105258d8a to your computer and use it in GitHub Desktop.
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

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

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