Hi guys
I’m new to Python and am currently doing a tutorial on how to create a Twitter bot using Tweepy.
I set up my Twitter developer account and managed to install Tweepy in Pycharm. I then pretty much copied the exact code the guy in the YT video is using, except it doesn’t work for me, while it works fine for him.
Here is what I get:
/usr/local/bin/python3.8 /Users/hg/Documents/HGAgencyBot/bot.py
Traceback (most recent call last):
File "/Users/hg/Documents/HGAgencyBot/bot.py", line 12, in <module>
api.update_status('twitter bot reporting in live')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tweepy/api.py", line 186, in update_status
return bind_api(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tweepy/binder.py", line 250, in _call
return method.execute()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tweepy/binder.py", line 233, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'code': 89, 'message': 'Invalid or expired token.'}]
And here is the Code I am working with:
import tweepy
consumer_key = '11316809803469600-PHZq5ddcmz2VcELnU4'
consumer_secret = 'o3vhc1RRjmY903793707350NCxx6NJN6drbRFzmNCpx'
key = 'plQA5TAxcS985308933bmnv7'
secret = 'PqXby4pRCG983058303vOF7m02hNt'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
api = tweepy.API(auth)
api.update_status('twitter bot reporting in live')
The only thing I have altered are my secret keys, the rest of the code is identical in my IDE (PyCharm) as well as in the tutorial where it works
2
Answers
Ok guys I found the answer, the token was not expired but it was invalid because I got them mixed up. Silly me.
Thanks to Salar for your contribution and anybody else who checked by.
Problem solved thank you!
I think you will need to use the secrets module for your keys because yours are different from the youtuber that you are watching