Reputation: 1
I need to get a users entire twitter timeline in python. I am using the following code with all the oauth keys:
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]
however, it returns [] for every account i try
I have no idea what im doing wrong. this is the first problem i've hade with python twitter.
Upvotes: 0
Views: 3578
Reputation: 235
Give it a try:
#!\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]
Upvotes: 2
Reputation: 2769
I think you have to change your second line as following:
api = twitter.Api(consumer_key='', consumer_secret='', access_token_key='', access_token_secret='')
There is no api
class, instead there is Api
. Please have a look at documentation.
Upvotes: 0