Skip to main content
 首页 » 编程设计

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

2025年05月04日7dudu

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 上找到有关此信息的更多详细信息。 .

希望这能解决问题!