How to automate an Instagram account without being discovered with Javascript

Esteve segura
3 min readSep 28, 2019

--

For a long time I was interested in automating an instagram account. From uploading photos, to obtaining suggestions / similar accounts from a user.

This has led me to make many attempts … Even with the original api, which was very serious mistake. I tried scrapy and seleium in python, also puppeteer in nodejs. None of that gave the result I expected, some due to slowness, others due to unexpected errors. I lost interest because of this and other problems.

But with new knowledge, new doors open.

There is a user on github who is developing a custom instagram api, that piece of software is called instagram-private-api developed by dilame and of course you don’t need instagram api credentials, only your instagram username and password.

I know what you’re thinking, is it safe to give my password to a private service?

In a case like this, YES, the project is open source and does not save, or send passwords anywhere, it is completely safe and if you do not believe me, you have the code there to read it.

If you are a novice or not very experienced programmer, using this project can be a bit tedious, due to the lack of extensive documentation.

That is why we are going to use a project that uses instagram-private-api and makes things much simpler, this project is called tools-for-instagram and is being developed by linkfy.

Let’s start with the code

Let’s start by creating a folder anywhere on our computer and starting our npm init

npm init --yes

First of all we install our packages via, we can run this in our terminal

npm install tools-for-instagram -s

Once installed, we have to create our .env file that will contain our username and password

sample of .env file

We will define the actions that our bot will perform

  • Give likes to photos of certain hashtags at defined intervals. Simulating human behavior.
  • Check for new direct messages on instagram, and show it by terminal.
  • Follow certain users per day

Start our code as follows. This configures different files and folders.

first login example

Save the file as “bot.js” and execute it in our console with the following command:

node bot.js

This will print the following log in our console:

sample log on login

Remember, this works under a nodejs environment, you must first have it installed

We also create the following file structure in the same folder where we have the file “bot.js”

folders and structure

All these files are necessary for the proper functioning of tools-for-instagram. Now we will proceed to create a structure that allows us to perform actions at certain times first we will give likes in certain hashtags.

Structure for schedule

We must also create a function to obtain all instagram publications based on the hashtags that we have specified above. Let’s call this function getPostsFromHashtags

getPostsFromHashtags function

Before continuing with the bot we need a random number generator. That is a very easy problem to solve. This function is enough for us.

random number generator

Then what we must do is give likes inside the hashtags using the likesPerInterval variable as a limit and using our function to generate random numbers, to simulate human behavior.

simulate human behavior on likes

And we can also do the same to follow people, changing the code a little

simulate human behavior on follows

And with this we already have our bot running. Ready to use. The possibilities are endless, tools-for-instagram is still in development depends on when you are reading this, the library may be very advanced, along with all its new features.

The download of the entire project will be available on github

Thank you very much for your time!

--

--

Esteve segura

Hi there! I'm Esteve Segura, Software Engineer based in Barcelona. I work at Voicemod as Tech Lead. I love swimming and cycling.