pythontwittertwitter-oauthpython-twitter

I want to have all the tweets of a userid not the latest 200 from twitter in python


I am using the python-twitter module to get the tweets of my friends. I used the following code:

import twitter

CONSUMER_KEY = ''
CONSUMER_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''

auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
                           CONSUMER_KEY, CONSUMER_SECRET)

twitter_api = twitter.Twitter(auth=auth)
count = 0
for tweets in twitter_api.statuses.user_timeline(screen_name="thekiranbedi",count=500):
    try:
        print tweets['text']
        count += 1
    except Exception:
        pass

print count

But as the result says, the value of count remains 200, so I am getting only the 200 recent tweets from the id with screen_name='thekiranbedi. But I want all the tweets. How can that be done?


Solution

  • That is a limitation of Twitter API, not of python-twitter module:

    https://dev.twitter.com/rest/reference/get/statuses/user_timeline

    count - Specifies the number of tweets to try and retrieve, up to a maximum of 200 per distinct request.

    So as I understood you have to use 'since_id' and 'max_id' arguments to collect next portion of tweets.