Last Updated: March 04, 2016
· tonyrain

Simple way to get the diff of followers and followed by in instagram

Hey guys, today was the day when my friend and i just simply having a dinner in some cafe and looking at feed's photos of our instagram accounts. Then he noticed that he left one follower from his account (what a big deal :D) and he wanted to know who did that "inhuman" action. The number of followers is up to 2K, so the idea to compare it manually not so good at all. After all of this i've decided to take a look at instagram api and decide to help him. Here i just wanted to share with you some simple code to find that diff. Don't judge me strict, cause it was really fast developed solution without any preparations, etc.

So, what we're going to start with. Let's install some node modules we'd like to have inside our project. Let's have there request-promise (for making server side requests), promise module q and lodash for some manipulations.

Also we'd like to have an ACCESS_TOKEN from the user we'd like to get that users diff. How to retrieve it you can read right in (official instagram docs. You will simply need your imstagram app's token to have ability to auth the user. Okay, i think this is not the topic of this tip, so let's go to the coding session and take a look at what i have for you.

So, here is (the link) to that gist i have to get instagram user's diff. The main part of code that initialises everything else is:

  promises.push(request(url.replace('{token}', ACCESS_TOKEN.PRIMARY)).then(remoteCallDecorator(function(data, deferred) {
    collectUsers(data).then(function(users) {

Here we're iterating via the api methods we're going to call and putting it inside promises array.
After all of this we're starting waiting for all promises to get been done via Q.all(promises) and string the process of calculating the diff between the users we're subscribed to and the one we're followed by.

Q.all(promises).then(function(usersList) {
  console.log([0], usersList[1]), function(user) { return user.username; }));

I hope this tip will be funny for you and you won't waste your time if you need to check who did unsubscribe from you :) Have a nice hacking guys!

This was really simple and fast gist made by me, so it's not so perfect as you can expect and i'll really appreciate if someone is going to add/refactor or even made some node module based on my solution. If someone is going to do it, i'd really like to participate (but not like the primary dev, cause now i have lack of time for it unfortunately). If someone finds it helpful, i might rewrite it to the better and extensible solution, but for now let it works the way it's now.