jlobos / instagram-web-api

🤳 Instagram Private Web API client for Node
https://npmjs.com/instagram-web-api
MIT License
1.12k stars 186 forks source link

updateChallenge w/ securityCode UnhandledPromiseRejectionWarning: StatusCodeError 400 #194

Open nicolauria opened 3 years ago

nicolauria commented 3 years ago

I am attempting to connect to the api using the following code. The console logged error is 'checkpoint_required'.

const Instagram = require('instagram-web-api');
const { igUsername, igPassword } = process.env
const ig = new Instagram({ username: igUsername, password: igPassword });

(async () => {

  try {
    await ig.login()
  } catch (err) {
    if (err.error && err.error.message === 'checkpoint_required') {
      console.log(err.error);
      const challengeUrl = err.error.checkpoint_url
      await ig.updateChallenge({ challengeUrl, securityCode: 670381 }).catch(err2 => {
        console.log(err2);
      }
    }
  }

  const profile = await ig.getProfile()
})()

The security code is one I received by email after trying to sign in. I am using the updateChallenge method but still getting an error. It is the updateChallenge method that is causing the error. I've tried catching and console logging the updateChallenge error but the object is quite large and I'm not sure where to look. Here is the top of the error message without the entire object from the catch block.

StatusCodeError: 400 - {"message":"","challenge":{"challengeType":"SelectVerificationMethodForm","errors":["This field is required."],"experiments":{},"extraData":{"__typename":"GraphChallengePage","content":[{"__typename":"GraphChallengePageBanner","banner_text":"Suspicious Login Attempt"},{"__typename":"GraphChallengePageHeader","description":null,"title":"We Detected An Unusual Login Attempt"},{"__typename":"GraphChallengePageText","alignment":"center","html":null,"text":"To secure your account, we'll send you a security code to verify your identity. How do you want to receive your code?"},{"__typename":"GraphChallengePageForm","call_to_action":"Send Security Code","display":"inline","fields":[{"__typename":"GraphChallengePageFormChoiceField","input_name":"choice","input_type":"choice","values":[{"label":"Phone: +1 ***-***-**92","selected":true,"value":0},{"label":"Email: n******a@o*****.com","selected":false,"value":1}]}],"href":null}]},"fields":{"choice":"0","fb_access_token":"None","big_blue_token":"None","google_oauth_token":"None","vetted_device":"None","phone_number":"+1 ***-***-**92","email":"n******a@o*****.com"},"navigation":{"forward":"/challenge/284726924/LrmSwqF9ba/","replay":"/challenge/replay/284726924/LrmSwqF9ba/","dismiss":"https://www.instagram.com/"},"privacyPolicyUrl":"/about/legal/privacy/","type":"CHALLENGE","challenge_context":"{\"step_name\": \"\", \"nonce_code\": \"LrmSwqF9ba\", \"user_id\": 284726924, \"is_stateless\": false}"},"status":"fail"}
William-McGonagle commented 3 years ago

I keep having this same problem too. This is my first time using the API, so I might just be doing something very wrong.

codexJoin commented 3 years ago

try :

(async() => {

    const client = new Instagram({username: 'username', password: 'password'});

    try {
        await client.login();

    }catch(err){
        if(err.error && err.error.message === 'checkpoint_required'){
            const challengeUrl = err.error.checkpoint_url;

            const test = await client.updateChallenge({ challengeUrl, choice: 1});

            const code = reader.question('Insert Code: ');

            await client.updateChallenge({challengeUrl, securityCode: code});
        }
    }

    await client.login();

    console.log("Ready!");

})();
arthurpadilha commented 3 years ago

@William-McGonagle, i've got this error too and it was related to the file format that I was trying to upload. Apparently this API doens't work well with .png format. I just converted the image file to JPEG (.jpg) and everything worked just fine. Hope it could help you.