Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommendations and advice for proxying #1789

Open
3 tasks done
imansyed0 opened this issue Jul 11, 2024 · 8 comments
Open
3 tasks done

Recommendations and advice for proxying #1789

imansyed0 opened this issue Jul 11, 2024 · 8 comments
Labels
question unconfirmed This issue hasn't been read/confirmed/accepted by an admin

Comments

@imansyed0
Copy link

General Question

Form

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

Question

I've set up Oxylabs residential proxying with session logic to reuse a given server at the geolocated country of the user if they try to log in more than once, but unfortunately Instagram is still flagging the logins as 'unusual' every time. Even after the user goes on Instagram and declares it was them that did the login, reattempting brings up the same error again, even though the proxy setup does then use the same server again for the rerequest. Anyone have advice on how to stop getting flagged as suspicious? Would ISP proxies help?

image

Code

async function loginToInstagram(username, password, verificationCode, challengeChoice, proxyUrl) {
  const ig = new IgApiClient();
  ig.state.generateDevice(username);

  const proxyAgent = new HttpsProxyAgent(proxyUrl);
  ig.request.defaults.agent = proxyAgent;

  let clientInfo = await loadClientInfo(username);
  if (!clientInfo) {
    clientInfo = {
      deviceId: ig.state.deviceId,
      phoneId: ig.state.phoneId,
      uuid: ig.state.uuid,
      adid: ig.state.adid,
      build: ig.state.build,
    };
    await saveClientInfo(username, clientInfo);
  } else {
    ig.state.deviceId = clientInfo.deviceId;
    ig.state.phoneId = clientInfo.phoneId;
    ig.state.uuid = clientInfo.uuid;
    ig.state.adid = clientInfo.adid;
    ig.state.build = clientInfo.build;
  }

  const cookieLoaded = await loadCookie(ig, username);
  if (cookieLoaded) {
    console.log('Cookies loaded, checking if session is valid...');
    try {
      if (await isLoggedIn(ig)) {
        console.log('Using existing valid session');
        return { ig, status: 'LOGGED_IN' };
      } else {
        console.log('Loaded session is no longer valid');
      }
    } catch (error) {
      console.log('Error checking login status:', error.message);
    }
  } else {
    console.log('No existing cookies found');
  }

  console.log('Proceeding with new login...');
  try {
    await ig.simulate.preLoginFlow();
    const loggedInUser = await ig.account.login(username, password);
    process.nextTick(async () => await ig.simulate.postLoginFlow());
    await saveCookie(ig, username);
    console.log('New login successful');
    return { ig, status: 'LOGGED_IN' };
  } catch (error) {
    if (error instanceof IgCheckpointError) {
      console.log('Checkpoint error occurred');
      ig.state.challengeUrl = error.response.body.challenge.url;
      
      await resetChallenge(ig);

      if (!challengeChoice) {
        const challengeInfo = await getChallengeChoices(ig);
        return { status: 'CHALLENGE_REQUIRED', challengeInfo };
      } else if (!verificationCode) {
        await ig.challenge.selectVerifyMethod(challengeChoice);
        return { status: 'VERIFICATION_CODE_NEEDED' };
      } else {
        const { body } = await ig.challenge.sendSecurityCode(verificationCode);
        if (body.logged_in_user) {
          await saveCookie(ig, username);
          return { ig, status: 'LOGGED_IN' };
        } else {
          throw new Error('Failed to solve challenge');
        }
      }
    }
    console.error('Login error:', error);
    throw error;
  }
}
@imansyed0 imansyed0 added question unconfirmed This issue hasn't been read/confirmed/accepted by an admin labels Jul 11, 2024
@wiz64
Copy link

wiz64 commented Jul 14, 2024

Having same issues i don't think its a proxy issue i cant even login just getting that 400 error

@wiz64
Copy link

wiz64 commented Jul 14, 2024

when i use deserealize i get this error, else just works

@wiz64
Copy link

wiz64 commented Jul 14, 2024

select verify method returns[Object: null prototype] { action: 'close', status: 'ok' }
seems like the api needs to be updated, even if i somehow pass this stage i get flagged while scraping

@sunmasters
Copy link

It's because you changed device data. Not because of proxy. If proxy has issues you will need OTP.
The challenge API is outdated in this library. So you can't pass challenge here.

@wiz64
Copy link

wiz64 commented Jul 15, 2024

It's because you changed device data. Not because of proxy. If proxy has issues you will need OTP.
The challenge API is outdated in this library. So you can't pass challenge here.

Nah device data is same but i am also getting an otp challenge I can't pass otp agreed, what's the solution to challenge?

Is there anyone who has done it already or let's do it !?

@martincanavate
Copy link

I have the same issue. An update for the challenge handler of this library would be great

@martincanavate
Copy link

did anyone manage to solve it?

@sunmasters
Copy link

Yes, can be solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question unconfirmed This issue hasn't been read/confirmed/accepted by an admin
Projects
None yet
Development

No branches or pull requests

4 participants