【问题标题】:Twython - Twitter API returned a 401Twython - Twitter API 返回 401
【发布时间】:2017-04-04 03:27:37
【问题描述】:

第一次使用 Twython 并遵循文档 here 中的示例。

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

我得到以下回复:

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.

有人可以提供一些指导吗?

谢谢!

【问题讨论】:

  • 啊 - 我应该使用apps.twitter.com 上的密钥,而不是这里生成的密钥。

标签: python twitter twython


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-12-19
    • 2016-12-24
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多