I like to automate things very much, so I was looking for a way to automate my Instagram account. I searched and looked for many ways and all of them seemed to be impossible. It is because Instagram doesn’t provide an API that can post images for you. After quite a few days of research, I came across a technique that would help us post to Instagram using an API – The Instagram-Private-API.
Instagram Private API
The Instagram Private API is kind of like a back door to Instagram where you can manipulate and control Instagram as to how you would do in the real mobile application. You can like, comment, share, publish stories, or even send a DM using this API. This API is not very famous because your account could be at risk if you use this API.
Here at offshorewritings.com, most of our social media interactions are automated. Thanks to Google’s Puppeteer, Heroku and Zapier. We have reduced the effort to publish to post our quotes and articles across various platforms. I’ve shared the code which can be used to login to Instagram and upload a photo for you through the API. There are also examples where you can post an image directly from a web URL.
The Code to post via API
You can use this code directly to post to Instagram from the API, just a couple of lines. Before using it make sure that you have the packages installed.
npm install instagram-private-api
Then you can use the following code to post your pictures. Make sure, the pictures are in proper resolution and aspect ratio. Instagram supports the aspect ratio of 4:5 and 1.91: 1. If your images are not in this resolution, you might get an error.
If you have any questions or queries, please let me know in the comments section. Happy to help. Also read my other blog posts where I talk about the difference between WordPress.com and WordPress.org. You can also try out the Free Online Image Quotes Generator developed by me to generate quotes online and download them instantly.