I'm going to collect tweets about an event that has been happened 3 years ago, but I read somewhere that Twitter only let its API users to collect tweets not older than a week. So, I'd like to ask if this is true, how can I collect tweets from 3 or more years ago?
Asked
Active
Viewed 439 times
0
-
check this https://stackoverflow.com/questions/24214189/how-can-i-get-tweets-older-than-a-week-using-tweepy-or-other-python-libraries – Jose Kj Sep 12 '17 at 19:02
2 Answers
1
Get tweets using:
time_line_statuses = api.GetUserTimeline(screen_name=screen_name, include_rts=True)
- Loop through time_line_statuses using a for loop
- Check "created_at" property of each item to see if it is younger than your cut off date.
- Each item has an "id" property. Value seems to grow with time. Lower ID = older.
- Store 'id' of oldest status from time_line_statuses as oldest_id.
- Call
.
time_line_statuses = api.GetUserTimeline(screen_name=screen_name, include_rts=True, max_id=)
Store oldest_id as previous_oldest_id
Repeat 1-6 while checking that oldest_id is not equal to previous_oldest_id before continuing the loop
You can only make 100 get request to twitter per hour. You need to count your Get() calls and have the program sleep for an hour when you've hit that limit. I don't know if their API has a limitation on how far back it can go. You may be able to save API calls if you can find the ID of the tweet that would be at the start of your cutoff date and seed this process from there.

WithMetta
- 381
- 1
- 5
-
2This would be a great answer if the question was to get tweets from a user timeline. It will not work for getting tweets that contain a word or hashtag corresponding to an event. – Jonas Sep 08 '17 at 20:51