dilame / instagram-private-api

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

[help] Stuck in challenge loop #417

Closed gold24park closed 6 years ago

gold24park commented 6 years ago

hi, when i try to create a session then i got "challenge_required" error.

{
  "message": "challenge_required",
  "challenge": {
    "url": "https://i.instagram.com/challenge/296014780/25TGkcz4sn/",
    "api_path": "/challenge/296014780/25TGkcz4sn/",
    "hide_webview_header": true,
    "lock": true,
    "logout": false,
    "native_flow": true
  },
  "status": "fail",
  "error_type": "checkpoint_challenge_required"
}

so i handled this error as described in repo's document.

MyInstagram.login = function (username, password, callback) {
    Client.Session.create(device, storage, username, password)
    .then(function(session) {
        return callback(null, session);
    })
    .catch(Client.Exceptions.CheckpointError, function(err) {
        return callback(err, challengeMe(err, username, password));
    });
}
function challengeMe(error, username, password){
    return Client.Web.Challenge.resolve(error, 'phone', true)
        .then(function(challenge){
            // challenge instanceof Client.Web.Challenge
            console.log(JSON.stringify(challenge));
            // Note: Challenge is global variable
            Challenge = challenge;
            // can be phone or email
            // let's assume we got phone
            if(!challenge.type !== 'phone') return;
            //Let's check if we need to submit/change our phone number
            return challenge.phone('+821075453171')
                .then(function(){return challenge});
        });
}

after receiving verification code, i call this method. It seems code verification works right, but when the code matches and calls login method again, 'Unhandled rejection NoChallengeRequired: No challenge is required to use account!' error occurs.

how can i get out of this loop?

// codeNumber: req.body.code
MyInstagram.code = function (codeNumber, callback) {
    if (Challenge.code(codeNumber)) {
        MyInstagram.login('myusername', 'mypassword', (err, session) => {
            if (err) return callback(err);
            return callback(null, session);
        });
    }
}

Note I changed some code on exceptions.js like this.

function CheckpointError(json, session) {
    this.json = json;
    this.name = "CheckpointError";
    this.message = "Instagram call checkpoint for this action!";
    if(_.isString(json.challenge.url))
        this.url = json.challenge.url;
    if(!this.url && _.isObject(json.challenge) && _.isString(json.challenge.url))
        this.url = json.challenge.url;
    if(!this.url)
        this.url = routes.getWebUrl('challenge')
    this.session = session;
}
sppmaster commented 6 years ago

I suggest you to change IP

pasevin commented 6 years ago

Most likely your IP got blacklisted. You should use good proxies instead. Meanwhile if you still experience issues with challenge loop, after switching the IP address, this might help: https://github.com/huttarichard/instagram-private-api/issues/394#issuecomment-361082147

ghost commented 6 years ago

I tried "Gramista" today and what the hell.. All accounts that I had trouble with at login (regardless of wheter with Python, Java or PHP API), Gramista has no problem to log in. I didnt even received an activation code via Email or a challenge warning.. nothing. How?

gold24park commented 6 years ago

@itemimg same here, maybe our account has been blocked.