在python中获取用户twitter时间线
我需要用python获取用户的整个twitter时间线。我将以下代码与所有oauth键一起使用:在python中获取用户twitter时间线,python,twitter,timeline,python-twitter,Python,Twitter,Timeline,Python Twitter,我需要用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 status
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上遇到的第一个问题。我认为您必须更改第二行,如下所示:
api = twitter.Api(consumer_key='', consumer_secret='', access_token_key='', access_token_secret='')
没有api
类,而是有api
。请看一下。试试看:
#!\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]
顺便说一句,它返回一个
TypeError:“module”对象不可调用