Self Portrait in Christmas BallThe other day I noticed/remembered that I had an instagram account. And, according to my sister, I was quite active on it. Apparently. I kept following new persons. That suprised me, so I logged on and investigated. “I” followed 974 (or so) persons I had never heard of… My first instinct was to delete the account.* But that would have been too easy, so I decided to investigate the Instagram-API to see if that could help me “get rid” (most) of the people I followed. And lo and behold I found this page - very promising, so I registered an app to get access to this. Since Instagram uses OAuth that landed me a client ID and a client secret.

Not awfully familiar with the innards of OAuth, I realized that for anything to work I would need an access token. Since this script was just for personal use, I figured I could just generate this once(ish) and use that to get access to my account. I followed the instructions on this (page): http://dmolsen.com/2013/04/05/generating-access-tokens-for-instagram/ to generate the token. The only change I did, since we want to be able to manipulate followers/relationships, was to add a “&scope=relationships” to the end of the url to get the pre-token “code”, like so:

(Admittedly, this took some trial and error and duckduckgoing to figure out…)

In the oven
Equiped with the resulting many character access token I set about to write a unfollowing script thingy using good old ruby, leveraging the already existing Instagram gem. One “gem install instagram” later I started hacking.
After setting up the Instagram object with the client id and secret, I actually only use the instagram gem for loading of the list of followers, like so:
I realized that I had some “real” followers that I do not want to unfollow, so before unfollowing any user I check to see that their id is not among my followers.

To do the actual unfollowing I just access the REST API directly using the HTTPI gem and my access token, like so:
The only problem with this approach is that the API has some restrictions on number of calls per day, so I need to keep running this script once a day for… quite some days.

*Well, that is a lie. First I changed the password...