1

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?

psr
  • 2,619
  • 4
  • 32
  • 57

1 Answers1

1

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.

  • I got that, but on the link https://dev.twitter.com/rest/reference/get/statuses/user_timeline it is written in the third paragraph that `This method can only return up to 3,200 of a user’s most recent Tweets. Native retweets of other statuses by the user is included in this total, regardless of whether include_rts is set to false when requesting this resource.` So there must be a way to get all the 3200 tweets in one line? – psr Sep 18 '15 at 05:08
  • I think that means if you start to look from 0 it will return 200, and if you start from 3120 tweet it will return only 80. – Stepan Tsymbal Sep 18 '15 at 05:11
  • You have to collect first 200 tweets, then check last tweet's ID. And put it in 'since_id' or 'max_id' argument. Then you get next 200. Sorry, I haven't checked that yet, it's only a thoughts. – Stepan Tsymbal Sep 18 '15 at 05:13
  • Worked well! Thank you :) – psr Sep 18 '15 at 05:16