I’m working on an app that grabs all of a user’s favorited tweets upon signup and later requests a user’s newly-favorited tweets upon user request.
Using twitter’s Working with timelines documentation, it’s pretty straight-forward to grab a user’s current favorited tweets using the
max_id parameter. Which starts at the very top of the list and works it’s way down.
The documentation also explains how to use the
since_id param to grab new tweets added to a timeline i.e. GET statuses / user_timeline and GET statuses / home_timeline. I figured this would be exactly what I needed in order to grab newly-favorited tweets. However, my assumption had one major flaw.
When a new tweet is added to the
home_timeline for example, that tweet is always added to the top of the list. Making the use of the
since_id param very useful in grabbing new tweets.
However, when favoriting a tweet, that newly-favorited tweet will not always get added to the top of a user’s favorite list.
A favorited-tweet gets added to a user’s favorite list depending on when that tweet was created not when that tweet was favorited. So if a user favorites a tweet created a week ago, it will get added somewhere below any other favorited-tweets that were created more recently. Now
since_id isn’t very useful because you can no longer say “Give me all the newly favorited tweets since the most recent tweet we already have in the database.”
The first obvious solution to solve this problem would be to always grab all of a user’s favorites and compare them to what you already have in the database and determine which ones you don’t already have. This however would be extremely inefficient. This would mean that you’d always have to request for tweets that you’ve already requested for and look through all the records in the database for a particular user.
The documentation for the GET favorites/list endpoint doesn’t provide any information about how to grab newly favorited tweets.
Has anyone solved this already or have any suggestions?