dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
6k stars 1.14k forks source link

Any Idea on how to solve the challenge with the Serverless approach? #1005

Closed haayhappen closed 4 years ago

haayhappen commented 4 years ago

General Question

Form

Put an [x] if you meet the condition, else leave [ ].

Question

Hi there, I'm using this lib in a Serverless Microservice. Does anyone have an idea to solve the challenge when running in a lambda with no possibility for user interaction to enter the code?

Thanks.

acollazo25 commented 4 years ago

I have not been working with this repository for a long time, I am sure there is a better solution, but I can show you something that works for me.

Login

/*...*/
.catch(IgCheckpointError, async () => {
    await ig.challenge.auto(true);
    await saveCheckpoint(ig.state.checkpoint, username);
/*...*/

Code Verfication

/*...*/
ig.state.checkpoint = await restoreCheckpoint(username);
const response = await ig.challenge.sendSecurityCode(code);
/*...*/

Save and Restore functions

async function saveCheckpoint(data: object, username) {
    const checkpointStatePath = `${process.env.IG_CHECKPOINT_PATH}/${username}.json`;
    await writeFile(checkpointStatePath, JSON.stringify(data), {flag: 'w'}, (e) => {
        if (e) throw e;
    });
}

async function restoreCheckpoint(username) {
    const checkpointStatePath = `${process.env.IG_CHECKPOINT_PATH}/${username}.json`;
    if (await existsSync(userCheckpointState)) {
        const data: string = await Bluebird.fromCallback(cb => readFile(checkpointStatePath, 'utf8', cb));
        return JSON.parse(data);
    }
}
tayfunyasar commented 4 years ago

call the function below.

https://github.com/dilame/instagram-private-api/blob/master/examples/checkpoint.example.ts

haayhappen commented 4 years ago

call the function below.

https://github.com/dilame/instagram-private-api/blob/master/examples/checkpoint.example.ts

Hi, this function requires the user to enter the Security Code manually. There is no way to access the cli of a running lambda function, so I need a way to get the code and delay lambda execution until that code is available and the run the function again.

tayfunyasar commented 4 years ago

You cant trick Instagram's manual verification process. There are multi layer manual operations like "SMS code", "This was me"(on device/browser that you logged in before) screen. Because Lambda functions are invoking themselves from different regions than your actual region. Instagram will force you to do than on each lambda invocation. And i think you already know that. ^_^

My Suggestion is:

PS: If you have a plan with different accounts in different IPs/Lambdas, Instagram has very strict bot detection mechanism so this plan isn't sustainable.