instagram-private-api
instagram-private-api copied to clipboard
IgUserIdNotFoundError: Could not extract userid (pk)
(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.
Node.js v18.19.1
R:\ig>
Maybe account is private or suspended