naer2 / instagramStoryDownloader

BEST Instagram Story Downloader for PHP - Instagram Story Saver for PHP
37 stars 13 forks source link

Infinite checkpoint challenge required #7

Closed recoverjp closed 4 years ago

recoverjp commented 4 years ago

Here, checkpoint_challenge_required appears every time, even after sending the code. Can anybody help me?

naer2 commented 4 years ago

Use with terminal.

recoverjp commented 4 years ago

I used the terminal, but it still doesn't work. After the script it says that the user is not logged in, and when I try to log in again ($ig->login()) he sends the code again via SMS and stays in the loop.

naer2 commented 4 years ago

I think it's about something your computer or IG account. I just check codes it's perfectly work.

recoverjp commented 4 years ago

When creating the account, do I need to configure anything specific? And another thing, I don't understand where this $user_id comes from, line 99.

naer2 commented 4 years ago

No. Everything works perfectly fine.

afwn90cj93201nixr2e1re commented 4 years ago

@recoverjp do u still need a help with that? U r right, there's undefined variable $user_id.

Is problem caused only with sms method? Did u tried email method?

afwn90cj93201nixr2e1re commented 4 years ago

The main problem can be caused by instagram security stuff, u need to login in account from web/phone and click on oppened window "That's was me" then u can continue with authorization.

изображение Under this dir @mgp25 api collects user's session tickets.

1) We can get difference result inside first customResponse

изображение (second try)

изображение (this is first time, also at first time we can get null, but it's also gonna send code via email)

изображение

Also i wanna notice that sometimes it's just continue sending 'first time auth' field (maybe it's realted to mgp25 api, idk).

So, seems like only one right way to imlpement it is, but possible we gonna get loop there, so, seems like old way is more clean.


catch (\Exception $exception) {
    $response = $exception->getResponse();
    echo "------------------getErrorType-----------".PHP_EOL;
    echo var_dump($response->getErrorType());
    echo "------------------getErrorType-----------".PHP_EOL;
    $fatalError = "Fatal error ".PHP_EOL;
    echo "------------------File1-----------".PHP_EOL;
    file_put_contents("fatals.txt",$fatalError,FILE_APPEND);
    echo "------------------File2-----------".PHP_EOL;
    file_put_contents("fatals.txt",print_r($response, true),FILE_APPEND);
    echo "------------------File3-----------".PHP_EOL;
    file_put_contents("fatals.txt",print_r($exception, true),FILE_APPEND);
    echo "------------------FileEnd-----------".PHP_EOL;
    // If error_type is checkpoint_challenge_required then we need try to pass challenge
    if ($response->getErrorType() === 'checkpoint_challenge_required') {
        sleep(3);
        // Getting api_path key from challenge array, removing first slash for future append
        $checkApiPath = substr($response->getChallenge()->getApiPath(), 1);
        // Trying to pass challenge
        $customResponse = $ig->request($checkApiPath)->
                            setNeedsAuth(false)->
                            addPost('choice', $verification_method)->
                            addPost('_uuid', $ig->uuid)->
                            addPost('guid', $ig->uuid)->
                            addPost('device_id', $ig->device_id)->
                            addPost('_uid', $ig->account_id)->
                            addPost('_csrftoken', $ig->client->getToken())->
                            getDecodedResponse();
    }
    else {
        exit;
    }
    try {
        echo "customResponse ------------------------------".PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL;
        echo var_dump($customResponse);
        echo "------------------------------".PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL.PHP_EOL;;
        $user_id = -1;
        if(isset($customResponse["status"]) && isset($customResponse["action"]) && $customResponse['status'] === 'ok' && $customResponse['action'] === 'close') {
            exit();
        }
        else if ($customResponse && isset($customResponse["step_name"])){
            $step_name = $customResponse["step_name"];
            if($step_name == "verify_email" || $step_name == "verify_code") {
                if(isset($customResponse["user_id"])) {
                    $user_id = $customResponse["user_id"];
                }
                echo 'Code that you received via '.($verification_method ? 'email' : 'sms');
                if(isset($customResponse["step_data"])) {
                    if(isset($customResponse["step_data"]["contact_point"])) echo ' ('.$customResponse["step_data"]["contact_point"].')';
                }
                $code = readln(":\n");
                if(isset($code)) {
                    $ig->changeUser($username, $password);
                    $customResponse = $ig->request($checkApiPath)->
                                        setNeedsAuth(false)->
                                        addPost('security_code', $code)->
                                        addPost('_uuid', $ig->uuid)->
                                        addPost('guid', $ig->uuid)->
                                        addPost('device_id', $ig->device_id)->
                                        addPost('_uid', $ig->account_id)->
                                        addPost('_csrftoken', $ig->client->getToken())->
                                        getDecodedResponse();
                    var_dump($customResponse);
                    if($customResponse && isset($customResponse["action"])&& isset($customResponse["status"])) {
                        if($customResponse["action"] == "close" && $customResponse["status"] == "ok") {
                            echo "Everything is fine (possible), visit instagram.com from browser and accept challenge (Press \"it was me\").".PHP_EOL;
                        }
                    }
                    else {
                        echo "Something went wrong".PHP_EOL;
                    }
                }
                else {
                    echo "Try again".PHP_EOL;
                }

            }
        }
        else if(isset($customResponse["status"]) && isset($customResponse["message"])) {
            echo "Failed with ".$customResponse["status"]." ".$customResponse["message"].PHP_EOL;
            // there we should remove cookies and settings
        } 
/*      

        if ($customResponse['status'] === 'ok' && (int) $customResponse['logged_in_user']['pk'] === (int) $user_id ) {
        } else {
            var_dump( $customResponse );
        } */
    }
    catch ( Exception $ex ) {
        echo $ex->getMessage();
    }
}
afwn90cj93201nixr2e1re commented 4 years ago

@recoverjp if u still have problems with that, try new version. There's more logs, and more info.

As i said u should accept auth. challenge on instagram website too, without that you gonna stay in loop. Mostly it should be aviable on: https://www.instagram.com/challenge/?next=/accounts/get_encrypted_credentials/, it's gonna redirect to this page automaticaly.

Also be careful with auth. challenge stuff. изображение