ammarbrohi / instagram-php

Instagram PHP API with Laravel Support - Unofficial
Other
3 stars 3 forks source link

Challenge Required in Instagram API? #6

Open emretuncer opened 3 years ago

emretuncer commented 3 years ago

There is a challenge problem with Instagram. I tried with many different proxy but nothing change.(In two factor authentication methods SMS, Backup Codes...) I deleted the session folder, but no luck. 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.

Code

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use InstagramAPI\Instagram;
class HomeController extends Controller
{

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('home');
    }

    public function test(Request $request){

        if($request->get('code')){
            $code = $request->get('code');
        }

        $username = "*****";
        $password = "*****";

        // Set allow dangerous
        Instagram::$allowDangerousWebUsageAtMyOwnRisk = true;

        $debug = false;
        $ig = new Instagram($debug, false);

        // Set proxy
        $ig->setProxy('**PROXY ADRESS**');

        try {

            $loginResponse = $ig->login($username, $password);
            print_r($loginResponse);
                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));
//                    $verificationCode = trim($code);
                    print_r($ig->finishTwoFactorLogin($username, $password, $twoFactorIdentifier, strval($code), '2'));

//                    }
                }
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
}
}

Debug Log


InstagramAPI\Response\LoginResponse: Challenge required.User not logged in. Please call login() and then try again.
mauriblint commented 3 years ago

i've the same problem trying to complete the 2F auth, could you resolve?