从tweepy获取“无效或过期的令牌”

问题描述

我昨天在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,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.'}]

解决方法

您发布的错误消息似乎与您的帖子标题不匹配。如果您的凭据有问题,我希望它在第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)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...