instagram-private-api icon indicating copy to clipboard operation
instagram-private-api copied to clipboard

IgUserIdNotFoundError: Could not extract userid (pk)

Open rssdevoloper opened this issue 1 year ago • 1 comments

(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>

rssdevoloper avatar Apr 11 '24 15:04 rssdevoloper

Maybe account is private or suspended

sunmasters avatar Jul 09 '24 19:07 sunmasters