【问题标题】:Getting "Invalid or expired token" from tweepy从 tweepy 获取“无效或过期的令牌”
【发布时间】:2020-08-19 21:55:36
【问题描述】:

我昨天在 Twitter 上开了一个开发者帐户并获得了批准。 我正在尝试学习如何使用 tweepy,但是在插入我的 API 凭据后,我在运行此代码时不断收到以下错误(我打乱了我的凭据)。 我三倍检查我输入的凭据是否正确。 有什么建议吗?

import tweepy


consumer_key = "AkFM0Lo9..." #API KEY
consumer_secret = "f5Txptjr8DePG34JOx..." #API key secret:
access_token = "hYt1Mwky0zGfRUqPKu8Lb..." #Access token:
access_token_secret = "MxzI4FD5HAX4GlXadjlc2..." #Access token secret:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)




auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

api.lookup_users(['hamid', 'python'])

错误信息:

Traceback (most recent call last):

  File "<ipython-input-33-bf513b9e8573>", line 20, in <module>
    api.lookup_users(['hamid', 'python'])

  File "C:\Users\yaniv_cfrphva\Anaconda3\lib\site-packages\tweepy\api.py", line 386, in lookup_users
    return bind_api(

  File "C:\Users\yaniv_cfrphva\Anaconda3\lib\site-packages\tweepy\binder.py", line 252, in _call
    return method.execute()

  File "C:\Users\yaniv_cfrphva\Anaconda3\lib\site-packages\tweepy\binder.py", line 234, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)

TweepError: [{'code': 17, 'message': 'No user matches for specified terms.'}]

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    您发布的错误消息似乎与您帖子的标题不匹配。如果您的凭据有问题,我预计它会在第 10 行出错。

    您也不需要这些第 15-18 行(您已经设置了一次凭据,因此这些是多余的)

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    
    api = tweepy.API(auth)
    

    要解决您的问题,请尝试:

    users=api.lookup_users("hamid","python")
    print(users)
    

    【讨论】:

      猜你喜欢
      • 2016-09-06
      • 2018-02-14
      • 2017-09-24
      • 2020-05-24
      • 2016-05-24
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 2014-05-15
      相关资源
      最近更新 更多