How to solve Challenge Required in Instagram mgp25 API?

2.6k Views Asked by At

I had a working script on my website named Instazood, which worked perfectly. Suddenly, a few days ago, I cannot use my script at all. Everything, it gives an error of "Challenge required". I verify that it was me on my Instagram, but when running the script I get the same error.

I deleted the session folder, but no luck.

I read here that the problem is because of different IPs. But all of my devices use the same internet, and I have no proxy at all.

I have below error.

Fatal error: Uncaught InstagramAPI\Exception\ChallengeRequiredException: InstagramAPI\Response\LoginResponse: Challenge required.uring import data.
2

There are 2 best solutions below

0
On

composer require adrifkat/instagram-api to download the package @tblanks1980

0
On

You need to use the two factor authentication methods provided by the library. Here is an example:

<?php

set_time_limit(0);
date_default_timezone_set('UTC');

require __DIR__.'/../vendor/autoload.php';

/////// CONFIG ///////
$username = '';
$password = '';
$debug = true;
$truncatedDebug = false;
//////////////////////

$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);

try {
    $loginResponse = $ig->login($username, $password);

    if ($loginResponse !== null && $loginResponse->isTwoFactorRequired()) {
        $twoFactorIdentifier = $loginResponse->getTwoFactorInfo()->getTwoFactorIdentifier();

        // The "STDIN" lets you paste the code via terminal for testing.
        // You should replace this line with the logic you want.
        // The verification code will be sent by Instagram via SMS.
        $verificationCode = trim(fgets(STDIN));
        $ig->finishTwoFactorLogin($username, $password, $twoFactorIdentifier, $verificationCode);
    }
} catch (\Exception $e) {
    echo 'Something went wrong: '.$e->getMessage()."\n";
}

On a related note, I am unable to download the package from GitHub since it was recently removed. Do you think you could upload just the mgp25/instagram-php package so that I can download it? I would be extremely grateful!!