我需要在python中获得用户整个Twitter的时间线。我使用以下代码和所有oauth键:
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 twitter讨厌的第一个问题。
答案 0 :(得分:1)
试一试:
#!\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]
答案 1 :(得分:0)
我认为您必须更改第二行,如下所示:
api = twitter.Api(consumer_key='', consumer_secret='', access_token_key='', access_token_secret='')
没有api
类,而是Api
。请查看documentation。