DEV Community

gooo.blog
gooo.blog

Posted on

Instagram Private API WEB- Node

Simple, easy implementation of the Instagram private web API.
Some API reference from jlobos/instagram-web-api
Send DM using client from dilame/instagram-private-api

How to install

npm i instagram-web-api-node
Enter fullscreen mode Exit fullscreen mode

How to use

const { IgApiClient } = require("instagram-web-api-node");
function save(data){
  let cookie = JSON.stringify(data); 
  //save cookie to file or database after 
  //code save
  return cookie;
}
(async () => { 
  try {
      const instagram = new IgApiClient();
      // This function executes after every request
      instagram.request.end$.subscribe(async () => {
        const serialized = await instagram.state.serialize();
        save(serialized); 
      });
      //set login account
      const { username, password } = process.env; 
      await instagram.state.generateDevice(); 
      //login use account username and password
      await instagram.ig.login(username, password);
  } catch (error){
      console.log(error.name)
  }
})();
Enter fullscreen mode Exit fullscreen mode

How to login without username and password

const { IgApiClient } = require("instagram-web-api-node");
(async () => { 
  try {
      const instagram = new IgApiClient();
      await instagram.state.deserialize(cookie); //cookiejson

      const follow = instagram.ig.follow(userid);
  } catch (error){
      console.log(error.name)
  }
Enter fullscreen mode Exit fullscreen mode

An example of a website that uses this API: Auto Followers Instagram

Top comments (0)