2012-11-21 56 views
0
#!/usr/bin/python 
# -*- coding: iso-8859-15 -*- 
import twitter 

class twitt(): 
    def __init__(self): 
     consumer_key = '...' 
     consumer_secret = '...' 
     access_key = '...' 
     access_secret = '...' 

     encoding = 'iso-8859-15' 

     self.api = twitter.Api(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token_key=access_key, access_token_secret=access_secret, input_encoding=encoding) 

    def run(self): 
     statuses = self.api.GetPublicTimeline() 
     print statuses 

h = twitt() 
h.run() 

此代碼不能正常工作,它直接取自自述和每一個例子,我發現。 我找到了關於「get_access_token.py」的東西,而且沒有提及它!?Python的嘰嘰喳喳 - 意想不到的關鍵字參數「access_token_key」

用戶@主持人:〜#updatedb的
用戶@主持人:〜#定位get_access_token
用戶@主持人:〜#

錯誤:TypeError: __init__() got an unexpected keyword argument 'access_token_key'

參考文獻:
- http://code.google.com/p/python-twitter/issues/detail?id=215
- https://github.com/bear/python-twitter/tree/master/examples

回答

0

API的版本錯誤。 正在使用支持用戶名/密碼認證的主要版本(僅限於?)。

使用twitter.py
已更新至0.8.4的 「0.6-devel的」 當時和它的作品,更好地..

編輯:

的API也已經過時,這不是」 t支持通過Twitter的Streaming API,這意味着你只會得到重要的帖子,我需要獲得標籤搜索的所有帖子。

我建議:
SixOhSix Twitter的API:https://github.com/sixohsix/twitter 使用方便,工作就像一個魅力,並得到你所需要的結果。

2

我可以LY認爲,也許twitter不是Twitter的庫你認爲它是:

嘗試看看,如果你得到一些與此類似:

>>> import twitter 
>>> twitter.__file__ 
'/usr/local/lib/python2.7/dist-packages/python_twitter-0.8.2-py2.7.egg/twitter.pyc' 

>>> import inspect 
>>> inspect.getargspec(twitter.Api.__init__) 
ArgSpec(args=['self', 'consumer_key', 'consumer_secret', 'access_token_key', 'access_token_secret', 'input_encoding', 'request_headers', 'cache', 'shortner', 'base_url', 'use_gzip_compression', 'debugHTTP'], varargs=None, keywords=None, defaults=(None, None, None, None, None, None, <object object at 0x7f023505a220>, None, None, False, False)) 
+0

+1 - 保持忘記檢查是多麼有用:) – RocketDonkey

+0

這可能會節省我一些時間。 雖然最主要的原因是我使用apt-get安裝的舊版本的庫python-twitter:/ – Torxed