How to automate an Instagram account without being discovered with Javascript
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
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.
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:
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”
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.
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
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.
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.
And we can also do the same to follow people, changing the code a little
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!