dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.92k stars 1.13k forks source link

IgUserIdNotFoundError: Could not extract userid (pk) #1772

Open rssdevoloper opened 4 months ago

rssdevoloper commented 4 months ago

(async () => {

const { IgApiClient } = require('instagram-private-api');

const fs = require("fs") const ig = new IgApiClient(); const username = "gaeun_lee_ig"; const password = "rangga20.";

const statePath = 'state';
let userId = ''; // or let userId: string;

if (fs.existsSync(statePath)) {
    console.log("Login session")
  const state = fs.readFileSync(statePath).toString()
  ig.state.deserialize(state)
  userId = ig.state.extractUserId();
} else {
    console.log("Login Akun")
  ig.state.generateDevice(username);

  const loggedInUser = await ig.account.login(
    username,
    password,
  );
  console.log(loggedInUser)
  userId = loggedInUser.pk.toString();

  const state = await ig.state.serialize();
  fs.writeFileSync(statePath, JSON.stringify(state));
}

const userInfo = await ig.user.info(userId);
const follower_count = userInfo.follower_count;

console.log(`User id: ${userId}`);
console.log(`Follower count: ${follower_count}`);

})();

R:\ig>node i.js Login session R:\ig\node_modules\instagram-private-api\dist\core\state.js:163 throw new errors_1.IgUserIdNotFoundError(); ^

IgUserIdNotFoundError: Could not extract userid (pk) at State.extractUserId (R:\ig\node_modules\instagram-private-api\dist\core\state.js:163:23) at R:\ig\i.js:20:22 at Object. (R:\ig\i.js:42:3) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) at node:internal/main/run_main_module:28:49

Node.js v18.19.1

R:\ig>

sunmasters commented 2 months ago

Maybe account is private or suspended