Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IgUserIdNotFoundError: Could not extract userid (pk) #1772

Open
rssdevoloper opened this issue Apr 11, 2024 · 1 comment
Open

IgUserIdNotFoundError: Could not extract userid (pk) #1772

rssdevoloper opened this issue Apr 11, 2024 · 1 comment
Labels
bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin

Comments

@rssdevoloper
Copy link

(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 rssdevoloper added bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin labels Apr 11, 2024
@sunmasters
Copy link

Maybe account is private or suspended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin
Projects
None yet
Development

No branches or pull requests

2 participants