2013-12-13 38 views
0

我需要在python中獲取用戶整個twitter時間線。我使用下面的代碼與所有的OAuth鍵值:在python中獲取用戶twitter時間線

import twitter 
api = twitter.api(consumer_key='', 
       consumer_secret='', access_token_key='', access_token_secret='') 
statuses = api.GetUserTimeline(username) 
print [s.text for s in statuses] 

但是,它返回[]爲每個帳戶我嘗試

我不知道什麼即時做錯了。這是我用Python嘰嘰喳喳討論的第一個問題。

+0

BTW它返回一個'類型錯誤: '模塊' 對象不callable' –

回答

0

我認爲你必須改變你的第二線如下:

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

沒有api類,而不是有Api。請看documentation

0

試試看:

#!\usr\bin\env python 

import twitter 

def oauth_login(): 
    # credentials for OAuth 
    CONSUMER_KEY = '' 
    CONSUMER_SECRET = '' 
    OAUTH_TOKEN = '' 
    OAUTH_TOKEN_SECRET = '' 
    # Creating the authentification 
    auth = twitter.oauth.OAuth(OAUTH_TOKEN, 
           OAUTH_TOKEN_SECRET, 
           CONSUMER_KEY, 
           CONSUMER_SECRET) 
    # Twitter instance 
    twitter_api = twitter.Twitter(auth=auth) 
    return twitter_api 

# LogIn 
twitter_api = oauth_login() 
# Get statuses 
statuses = twitter_api.statuses.user_timeline(screen_name='SpongeBob') 
# Print text 
print [status['text'] for status in statuses] 
相關問題