Open BilalTaner opened 9 months ago
Any solution? I'm having the same error
This works for me:
const ig = new IgApiClient();
const statePath = 'state';
let userId: string;
if (fs.existsSync(statePath)) {
const state = fs.readFileSync(statePath).toString();
ig.state.deserialize(state);
userId = ig.state.extractUserId();
} else {
ig.state.generateDevice(process.env.IG_USERNAME);
const loggedInUser = await ig.account.login(
process.env.IG_USERNAME,
process.env.IG_PASSWORD,
);
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}`);
@sercanersoy Thank you!
We used to have ig.state.generateDevice
before deserializing the cookie. After upgrading the library, this results in the login not working anymore if the session cookie cannot be deserialized.
The solution is to move ig.state.generateDevice(…)
just before the login and not call it when deserializing from cookie
This works for me:
const ig = new IgApiClient(); const statePath = 'state'; let userId: string; if (fs.existsSync(statePath)) { const state = fs.readFileSync(statePath).toString(); ig.state.deserialize(state); userId = ig.state.extractUserId(); } else { ig.state.generateDevice(process.env.IG_USERNAME); const loggedInUser = await ig.account.login( process.env.IG_USERNAME, process.env.IG_PASSWORD, ); 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}`);
To use this solution I needed to add a "await" before ig.state.deserialize(state)
General Question
Read the Notes and fill out the form.
Even though I log in with a cookies, my login function works every time I use any command. That's why I'm constantly blocked by Instagram. What should I do?
ERROR-1 (I made a counter for find requests.)