Jump to content
Welcome, welcome! Come in and register, and have some developer coffee. 👨‍💻 ×

[Node.js] Upload Image To Instagram From Your PC Under 10 Lines of Code


Recommended Posts

Sup, GG fams!

If you use Instagram, you probably already know that they only provide and allow media uploads on mobiles (REDIKULUS I KNOW!!!). 

 

Today, we'll be trying out an unofficial Instagram API provider, Tools-for-Instagram. They claim to have an AI that can help reduce the risk of ban. You probably want to test it out on an useless account to keep your main account safe!

 

Aaaaaaand here's the good news. I've been using their API since Nov 2020, and I'm now at my 1107th memes with 0 bans (including soft ban).

 

image.png

 

That stats aren't that great though. I'm assuming high chance it's because of the set of hash tags used. I have been putting it to run automatically since Nov 2020 to post on every hour.

 

Alright, here's how you can create the uploader:

 

Requirement

 

In this tutorial, we'll assume that you already know how to create a node script, so let's start by installing the library. Run the following command in your project folder:

npm install tools-for-instagram

 

Next you'll need to create a .env file in your root folder and paste in the following.

IG_USERNAME=USERNAME
IG_PASSWORD=PASSWORD
#ONLINE_MODE=true
#IG_PROXY=http://proxyuser:[email protected]:xxxxx
#IG_VERIFICATION=sms
#IG_VERIFICATION=email
#IG_VERIFICATION=otp

Replace username and password with your IG username and password.

 

Create an self-executing async function in your index.js and perform login.

require("tools-for-instagram");

(async () => {
  const ig = await login();
})();

 

There are several ways that you can upload you images. To upload a single image with an image URL, use the uploadPictureByUrl api:

require("tools-for-instagram");

(async () => {
  const ig = await login(); //Perform login
  const caption = "Some random meme. #meme"; //Image caption
  
  const rsp = await uploadPictureByUrl(ig, caption, 'https://i.pinimg.com/474x/d6/cb/00/d6cb008bc1291154467fd223ec8df556.jpg');
  console.log(rsp)
})();

 

You can also upload an image from your local computer. Create an image folder and dump your image file inside. I'm hardcoding the image file to image.jpg for now, but you can use fs.readdir to dynamically read the image name (homework!).

 

require("tools-for-instagram");
const path = require('path');

(async () => {
  const ig = await login();
  const caption = "Some random meme.";

  let imagePath = path.join(__dirname, '/images/image.jpg');
  const rsp = await uploadPicture(ig, caption, imagePath);
})();

 

That's it. You can now upload images from your computers easily.

 

Extra

To make things more exciting, you can create a bat file to automatically launch the node script on execution. Create a bat file called upload.bat in your project root with the following content:

node index.js

 

Now when you double click the bat file, your script should launch. It's extremely convenient and you'll only need to dump in your image file into the /image folder and launch the script tp upload. Easy, huh?

 

Show us your work in the comment!

 

The following project can be found on your GitHub here.

 

Have have, GG Kakis!

  • Love 1
  • Thanks 1
Link to post
Share on other sites
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...