简体   繁体   English

Twython-Twitter API返回了401

[英]Twython - Twitter API returned a 401

First time using Twython and following an example found in the docs here . 首次使用Twython并遵循此处文档中的示例。

from twython import Twython



APP_KEY='my_key'
APP_SECRET='my_secret'
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens()

OAUTH_TOKEN=auth['oauth_token']
OAUTH_TOKEN_SECRET=auth['oauth_token_secret']

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN,OAUTH_TOKEN_SECRET)


results = twitter.cursor(twitter.search, q='BarackObama')
for result in results:
    print result

I am getting the following back: 我得到以下信息:

Traceback (most recent call last):
  File "/Users/%USER%/PycharmProjects/WebGatherBusiness/twitter_experiments.py", line 26, in <module>
    for result in results:
  File "/Library/Python/2.7/site-packages/twython/api.py", line 478, in cursor
    content = function(**params)
  File "/Library/Python/2.7/site-packages/twython/endpoints.py", line 230, in search
    return self.get('search/tweets', params=params)
  File "/Library/Python/2.7/site-packages/twython/api.py", line 264, in get
    return self.request(endpoint, params=params, version=version)
  File "/Library/Python/2.7/site-packages/twython/api.py", line 258, in request
    api_call=url)
  File "/Library/Python/2.7/site-packages/twython/api.py", line 194, in _request
    retry_after=response.headers.get('X-Rate-Limit-Reset'))
twython.exceptions.TwythonAuthError: Twitter API returned a 401 (Unauthorized), Invalid or expired token.

Could someone please provide some guidance? 有人可以提供一些指导吗?

Thank you! 谢谢!

您应该使用apps.twitter.com上的密钥,而不要使用通过get_authentication_tokens生成的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM