so I run this
const { IgApiClient } = require("instagram-private-api");
const fs = require("fs");
const path = require("path");
const readline = require("readline");
const IG_USERNAME = "username";
const IG_PASSWORD = "password";
const SESSION_FILE_PATH = path.join(__dirname, "session.json");
async function main() {
const ig = new IgApiClient();
ig.state.generateDevice(IG_USERNAME);
if (fs.existsSync(SESSION_FILE_PATH)) {
try {
const saved = JSON.parse(fs.readFileSync(SESSION_FILE_PATH, "utf-8"));
await ig.state.deserialize(saved);
console.log("✅ Session restored");
} catch {
console.log("⚠️ Failed to restore session");
}
}
await ig.simulate.preLoginFlow();
try {
const loggedIn = await ig.account.login(IG_USERNAME, IG_PASSWORD);
console.log("✅ Logged in as:", loggedIn.username);
} catch (err) {
if (err.name === "IgLoginTwoFactorRequiredError") {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const twoFactorCode = await new Promise((resolve) => rl.question("Enter 2FA code: ", (code) => { rl.close(); resolve(code); }));
const loggedIn = await ig.account.twoFactorLogin({
username: IG_USERNAME,
verificationCode: twoFactorCode,
twoFactorIdentifier: err.response.body.two_factor_info.two_factor_identifier,
trustThisDevice: "1",
});
console.log("✅ Logged in with 2FA as:", loggedIn.username);
} else {
console.error("❌ Login failed:", err.message || err);
return;
}
}
const serialized = await ig.state.serialize();
delete serialized.constants;
fs.writeFileSync(SESSION_FILE_PATH, JSON.stringify(serialized));
console.log("💾 Session saved");
const me = await ig.account.currentUser();
console.log("👤 Profile info:", { username: me.username, fullName: me.full_name, pk: me.pk });
}
main().catch(console.error);
and the error
"❌ Login failed: POST /api/v1/accounts/login/ - 400 Bad Request; We can't find an account with darkphoenixv3. Try another phone number or email, or if you don't have an Instagram account, you can sign up."
is returned even though my username and password is correct...any ideas?? thank you in advance.
so I run this
and the error
"❌ Login failed: POST /api/v1/accounts/login/ - 400 Bad Request; We can't find an account with darkphoenixv3. Try another phone number or email, or if you don't have an Instagram account, you can sign up."
is returned even though my username and password is correct...any ideas?? thank you in advance.