I use the favourites feature of Twitter as a bookmarking service. Every few days I go through some and unfavourite as I deal with each one. Unfortunately I favourite far more than I am able to deal with later so the count has recently grown to 1365 favourites, with some dating back up to three years! So I've decided it is time to declare bankruptcy.
I figured that partly what was slowing me down is that Twitter does not provide any way to sort or filter the favourites. Nor does it provide a way to bulk manage or export the favourites. So I turned to the API. Turns out Twitter has a nice, easy way to get favourites and return them as JSON:
https://api.twitter.com/1/favorites.json?screen_name=yourname
But this only returned the most recent favourites. Further digging showed that a count parameter can be added:
https://api.twitter.com/1/favorites.json?screen_name=yourname&count=1365
But Twitter only wants to send back approximately 200 at a time, though it does allow for pagination. So 1365 divided by 200 is six and a bit, so I need seven pages. I tried doing this with cURL and a loop but something wasn't working so did it manually and stored the output in seven files:
https://api.twitter.com/1/favorites.json?count=199&screen_name=lewiswalsh&page=2
Now all I needed to do was load the files as JSON, decode them to a data structure and drop them in to a CSV and a database. Each favourite returned has a LOT of information with it, but all I needed was the tweet itself, the date and the author.
Since most of my favourites are links to things I want to view or read later it was a simple matter to create a fourth field in my database called 'tag' and using LIKE '%http://%' in an UPDATE query I was able to tag over 1100 of my favourites with a tag 'link'. Since Twitter uses URL-shortening I reasoned searching for '%https://%' would be fruitless. The little one hundred remaining un-tagged I went through manually and tagged with various tags such as 'tip' and 'quote'.
Now all my old favourites and searchable, sortable and easily displayed in any way I see it. I thought it might also be useful to see who I favourite a lot of.
Now all I need to do is figure out a fast way to delete 1365 favourites from Twitter itself!