试图通过Tweepy & Twitter API创建推特。

问题描述 投票:0回答:1

大家好

我是Python新手,目前正在做一个关于如何使用Tweepy创建一个Twitter机器人的教程.我设置了我的Twitter开发者账户,并设法在Pycharm中安装Tweepy。然后,我几乎复制了YT视频中那个人使用的代码,只是它对我不起作用,而对他却很好。

这是我得到的结果。

/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')

我唯一修改的是我的密匙 其余的代码在我的集成开发环境(PyCharm)里是一样的 也在教程里是一样的。

python tweepy
1个回答
0
投票

我想你需要使用秘密模块来处理你的密钥,因为你的密钥和你正在看的那个uber不同。


0
投票

好了各位我找到答案了,令牌没有过期,但是因为我把它们弄混了,所以无效。我真傻。

感谢Salar的贡献和其他检查过的人。

问题解决了,谢谢你

© www.soinside.com 2019 - 2024. All rights reserved.