K
K
kr_ilya2020-05-05 12:34:14
Node.js
kr_ilya, 2020-05-05 12:34:14

Why doesn't instagram-private-api cookie authorization work?

Library
I am making a project using this library.
I tried to add authorization by saved cookies, but apparently I'm doing something wrong, because I continue to receive emails about authorization to my account.
Is cookie authorization correct?
Here is my code

import { IgApiClient } from '../src';
import { readFile, appendFileSync, writeFile } from 'fs';
import * as os from 'os';
import { config } from './config';

import { promisify } from 'util';

const readFileAsync = promisify(readFile);

const IG_USERNAME = config.instLogin;
const IG_PASSWORD = config.instPass;

const ig = new IgApiClient();

function fakeSave(data: object) {
  writeFile('session.txt', JSON.stringify(data), (err) => {
    if (err) throw err;
  });
  return data;
}

async function fakeExists() {
    let d = await readFileAsync('session.txt', "utf8");
    if(d){ 
      return true;
    }else{
      return false;
    }
}

async function fakeLoad() {
  let cook = await readFileAsync('session.txt', "utf8");
  return JSON.parse(cook.toString());
}

async function login() {
    // This function executes after every request
  ig.request.end$.subscribe(async () => {
    const serialized = await ig.state.serialize();
    delete serialized.constants; // this deletes the version info, so you'll always use the version provided by the library
    fakeSave(serialized);
  });
  let fe = await fakeExists();

  if (fe) {
  	console.log('FE');
    // import state accepts both a string as well as an object
    // the string should be a JSON object
    await ig.state.deserialize(await fakeLoad());
  }else{
  	console.log('LOGIN');
  	  ig.state.generateDevice(IG_USERNAME);
    await ig.account.login(IG_USERNAME,IG_PASSWORD);
  }
}
// console.log(process.argv);
(async () => {
  await login();
...
});


FE hits the console every time. That is, ig.account.login is essentially not called, but Instagram still captures authorization with each call.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question