Collecting old tweets through Tweeter API

461 Views Asked by At

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?

2

There are 2 best solutions below

1
On

Get tweets using:

time_line_statuses = api.GetUserTimeline(screen_name=screen_name, include_rts=True)
  1. Loop through time_line_statuses using a for loop
  2. Check "created_at" property of each item to see if it is younger than your cut off date.
  3. Each item has an "id" property. Value seems to grow with time. Lower ID = older.
  4. Store 'id' of oldest status from time_line_statuses as oldest_id.
  5. Call

.

time_line_statuses = api.GetUserTimeline(screen_name=screen_name, include_rts=True, max_id=)
  1. Store oldest_id as previous_oldest_id

  2. 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.

0
On

Your only option is to pay for a service such as Gnip. Gnip provides an API that will let you search for tweets older than one week.