dilame / instagram-private-api

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

Unable to resolve "this was me" challenge with ig.challenge.auto(true) #880

Closed DKertson16 closed 4 years ago

DKertson16 commented 5 years ago

So I've looked through all the issues and examples and I still cannot get this to work so sorry if I am missing something simple. I am successfully able to login with two of my accounts with no challenges necessary, but I get IgCheckpointError on a friend's account that I am trying to use. I am using a third party proxy with all of my requests. My code looks like so:

console.log('request received...')
  ig = new IgApiClient();
  ig.state.generateDevice(username);
  // apply agent class to request library defaults
  ig.request.defaults.agentClass = shttps;
  ig.request.defaults.agentOptions = {
    // @ts-ignore
    socksHost: '@@@', // proxy hostname
    socksPort: 0000,
    socksUsername: '0000',
    socksPassword: '000',
  };

  console.log("authenticating...");
  bluebird.try(async () => {
    process.nextTick(async () => await ig.simulate.postLoginFlow());
    auth = await ig.account.login(username, password);
    console.log("successfully authenticated")
    generateFollowers(response)

  }).catch(IgCheckpointError, async () => {
    console.log("authentication requires challenge...");
    console.log("checkpoint info:");
    console.log(ig.state.checkpoint);
    console.log(await ig.challenge.auto(true));
    console.log("challenge info:");
    console.log(ig.state.checkpoint);
    // const { code } = await inquirer.prompt([
    //   {
    //     type: 'input',
    //     name: 'code',
    //     message: 'Enter code',
    //   },
    // ]);
    // console.log(await ig.challenge.sendSecurityCode(code));
    console.log("successfully authenticated!")
    generateFollowers(response)
  })

As you can see I have commented out the sendSecurityCode part of it because I am not receiving a code and the ig.state.checkpoint is null at that point. I have tried with and without the security code part and nothing seems to work, and I usually get 'Unhandled rejection IgResponseError: POST /api/v1/challenge/reset/3662491500/iOHcynqQAa/ - 500 Internal Server Error;'

niedfelj commented 5 years ago

Why are you using nextTick?

ju5td0m7m1nd commented 4 years ago

@niedfelj Want to know what is the difference between using nextTick and not

romshiri commented 4 years ago

Having the same issue. Does anyone have a solution or a way to workaround this?

messilao commented 4 years ago

i have same issue. i don't login instagram via app and web instagram.

Axiver commented 4 years ago

This issue still exists. Hopefully someone has a solution

Nerixyz commented 4 years ago

This issue still exists. Hopefully someone has a solution

Could you paste the challenge data (error.response.body) here? There are different challenges out there and some require different requests.

Axiver commented 4 years ago

@Nerixyz Here ya go:

{ message: 'challenge_required', challenge: { url: 'https://i.instagram.com/challenge/22727428120/BeUNWGs83Y/', api_path: '/challenge/22727428120/BeUNWGs83Y/', hide_webview_header: true, lock: false, logout: false, native_flow: false }, status: 'fail' }

Axiver commented 4 years ago

I think it's worth noting that I don't get a error code 500 from their server; I get code 400 instead.

IgCheckpointError: POST /api/v1/challenge/reset/22727428120/M4XOzNpLlY/ - 400 Bad Request; challenge_required

However, I am following the example given as well. It fails at await ig.challenge.auto(true)

Code;

Bluebird.try(async () => {

    const auth = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);

    console.log(auth);

  }).catch(IgCheckpointError, async () => {

    console.log(ig.state.checkpoint); // Checkpoint info here

    await ig.challenge.auto(true); // Requesting sms-code or click "It was me" button

    console.log(ig.state.checkpoint); // Challenge info here

    const { code } = await inquirer.prompt([

      {

        type: 'input',

        name: 'code',

        message: 'Enter code',

      },

    ]);

    console.log(await ig.challenge.sendSecurityCode(code));

  });
Nerixyz commented 4 years ago

hide_webview_header: true, native_flow: false

This is a web challenge. It isn't handled by the "native" API. Instead, a webview is created and the challenge is processed there. However, you can emulate this. I don't know if my way is still correct, but it should work (there's a lot of stuff logged to the console): https://gist.github.com/Nerixyz/7f65bc19e5e666865a2682fb509a5d83 Maybe you don't need to change the password (the response will be very short), then just end the script and login again.

Nerixyz commented 4 years ago

This thread has been inactive for a long time now, so it will be closed. If this is still an issue, reopen it.