twitter-python - 在文档后面出现错误

时间:2014-01-28 20:54:39

标签: python twitter

在python2.7下已经安装了twitter-python Building section

中的requirements.txt

这是我第一次跳入,并按照基本步骤确保此链接twitter-python Documentation section中所述的一切正常,我收到错误。

这里是命令行Python shell的输入:

>>> api = twitter.Api(consumer_key='consumer_key',
                   consumer_secret='consumer_secret',
                   access_token_key='access_token',
                   access_token_secret='access_token_secret')

错误:

>>> print api.VerifyCredentials()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/.virtualenvs/twitter/local/lib/python2.7/site-  packages/python_twitter-1.2-py2.7.egg/twitter.py", line 5209, in VerifyCredentials
data = self._ParseAndCheckTwitter(json.content)
File "/home/ubuntu/.virtualenvs/twitter/local/lib/python2.7/site-packages/python_twitter-1.2-py2.7.egg/twitter.py", line 5462, in _ParseAndCheckTwitter
self._CheckForTwitterError(data)
File "/home/ubuntu/.virtualenvs/twitter/local/lib/python2.7/site-packages/python_twitter-1.2-py2.7.egg/twitter.py", line 5487, in _CheckForTwitterError
raise TwitterError(data['errors'])
twitter.TwitterError: [{u'message': u'Invalid or expired token', u'code': 89}]

我可以在这里找到什么?

2 个答案:

答案 0 :(得分:3)

您需要将'consumer_key''consumer_secret''access_token''access_token_secret'替换为实际值。您可以将这些值直接放在twitter.Api()调用中,也可以将它们的值赋给变量:

>>> # all these values are just random, you'll need to use your own values
>>> c_key = '123456'
>>> c_secret = 'a88d098cd76'
>>> token = '98765'
>>> token_secret = 'ad98c63e87f00'
>>> api = twitter.Api(consumer_key=c_key,
                      consumer_secret=c_secret,
                      access_token_key=token,
                      access_token_secret=token_secret)

答案 1 :(得分:1)

我不确定,但看起来你需要一个有效的consumer_key,consumer_secret,access_token_key和access_token_secret。这将涉及您在twitter.com上设置自己的应用程序并使用消费者密钥/秘密和测试access_token密钥/秘密来开始。