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

标签 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'

最佳答案

有几个原因导致了您的问题。

1)Permission denied错误(error:/usr/local/lib/python2.7/dist-packages/twitter.py: Permission denied)是因为你没有管理员权限。尝试 sudo python setup.py install

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

希望这能解决问题!

关于python - 为什么我不能从 Python 发送推文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9584229/

相关文章:

python - python的哈希函数在不同版本之间是否保持相同?

Python MySQL 返回表数据 - 仅在一行中显示所有内容

python - 如何删除文件中两个重复 block 之一?

json - 如何使用 api 在 Facebook 上发布 gif

python - 使用来自 JSON 响应的数据

python - Python 中的矛盾输出

php - 在 Paypal Express Checkout 订单完成后发送电子邮件

json - 带有已安装库的 Python 3.1 推特帖子,

java - 通过 JSON 提要代码下载推文无效

php - Twitter API - 计算特定字符串的推文数量