1

I was trying to run the following code and I get variable number of tweets when I keep running the code at some interval of time (more than 15min). Sometimes I get 1400 tweets and 1200,1000,1600 tweets the other time. Can't I get fixed number of tweets all the time I run the code even if i change the keyword?

for tweet in tweepy.Cursor(api.search, q="#narendramodi", rpp=100).items(200):

asdf
  • 25
  • 8

1 Answers1

0

You search does not specify any id limit.

Because of pagination, Twitter Search API looks for latest tweets every time you call it. Since tweets are added continuously, simple call to Search API returns the most recent ones and you'll get different number of tweets based on how many tweets were posted during the time you were querying. See Working with Timelines.

Please also note that Twitter Search API focuses on relevance rather than completeness of the results. See The Search API.

If you want to iterate over tweets, starting from the moment you run your application and continuing to older tweets, I recommend using max_id in your next query parameters setting it with the id field of the last result from your query as suggested here.

Community
  • 1
  • 1
Milad.H
  • 116
  • 4
  • How do I use max_id parameter in my code? @Milad.H for tweet in tweepy.Cursor(api.search, q="#narendramodi",max_id=str(last_id - 1)).items(200): This dint work – asdf Mar 05 '17 at 08:44