为什么我不能从Python发送推文?

时间:2012-03-06 13:01:32

标签: python api twitter

import twitter

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

friends=api.PostUpdate("First Tweet from PYTHON APP ")

我已按照http://abhi74k.wordpress.com/2010/12/21/tweeting-from-python/的说法完成了所有操作,但当我在里面完成并按回车键时,没有任何反应。你能帮帮我吗?

好的,因为我无法正确下载python-twitter API。当我尝试遵循这些步骤时,它会给我这个错误:

figen@figen-Satellite-A350:~/Downloads/python-twitter-0.8.2$ python setup.py install
running install
running build
running build_py
running install_lib
copying build/lib.linux-x86_64-2.7/twitter.py -> /usr/local/lib/python2.7/dist-packages
error: /usr/local/lib/python2.7/dist-packages/twitter.py: Permission denied

http://code.google.com/p/python-twitter/

好的,我安装了setup.py,但现在它出现了这个错误:

figen@figen-Satellite-A350:~/Downloads/python-twitter-0.8.2$ python twitter_test.py
Traceback (most recent call last):
  File "twitter_test.py", line 29, in <module>
    import twitter
  File "/home/figen/Downloads/python-twitter-0.8.2/twitter.py", line 65, in <module>
    import oauth2 as oauth
ImportError: No module named oauth2

现在它说twitter模块没有模块。如何获得它?

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

  friends=api.PostUpdate("If you see this,I managed to send my first tweet from Python    Shell. Yay! =)")
  Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
  api = twitter.Api(consumer_key='removed for security=)',
  AttributeError: 'module' object has no attribute 'Api'

2 个答案:

答案 0 :(得分:1)

导致问题的原因有很多。

1)权限被拒绝错误(错误:/usr/local/lib/python2.7/dist-packages/twitter.py:权限被拒绝)是因为您没有管理员权限。试试sudo python setup.py install

2)您需要安装缺少的依赖项(即oauth2),您可以从此处获取oauth2 http://github.com/simplegeo/python-oauth2确保您具有所需的其他依赖项,即SimpleJson和HTTPLib2。您可以在python-twitter-api site上找到有关此信息的更多详细信息。

希望这能解决它!

答案 1 :(得分:-1)

您需要安装包含Api的Twitter。 http://code.google.com/p/python-twitter/downloads/detail?name=python-twitter-0.8.2.tar.gz此版本包含Api。