Подскажите, где ошибся?
выдает
Undefined index: user_id
var_dump($customResponse); === { ["message"]=> string(23) "This field is required." ["status"]=> string(4) "fail" }
при
$debug = false;
$truncatedDebug = false;
$user_id = '';
$challenge_id = '';
$verification_method = 0; //0 = SMS, 1 = Email
function readln($prompt) {
if ( PHP_OS === 'WINNT' ) {
echo $prompt;
return trim( (string) stream_get_line( STDIN, 6, "\n" ) );
}
return trim(readline("$prompt"));
}
Instagram::$allowDangerousWebUsageAtMyOwnRisk = true;
$ig = new Instagram($debug, $truncatedDebug);
try{
$loginResponse = $ig->login($request->login, $request->password);
$user_id = $ig->account_id;
if ( $loginResponse !== null && $loginResponse->isTwoFactorRequired() ) {
return '2FA not supported in this example';
}
if ( $loginResponse instanceof LoginResponse || $loginResponse === null ) {
return "Not a challenge required exception...\n";
}
return 'Logged in!';
}catch (\Exception $e) {
if ( ! method_exists( $e, 'getResponse' ) ) {
echo $e->getMessage();
exit;
}
$response = $e->getResponse();
var_dump($response);
if ($e instanceof ChallengeRequiredException) {
sleep(5);
$customResponse = $ig->request(substr($e->getResponse()->getChallenge()->getApiPath(), 1))->setNeedsAuth(false)->addPost("choice", 0)->getDecodedResponse();
var_dump($customResponse);
if (is_array($customResponse)) {
$user_id = $customResponse['user_id'];
$challenge_id = $customResponse['nonce_code'];
} else {
//Other stuff.
}
try {
$code = readln( 'Code that you received via ' . ( $verification_method ? 'email' : 'sms' ) . ':' );
$customResponse = $ig->request( "challenge/$user_id/$challenge_id/" )->setNeedsAuth( false )->addPost( 'security_code', $code )->getDecodedResponse();
if ( ! is_array( $customResponse ) ) {
echo "Weird response from challenge validation...\n";
//var_dump( $customResponse );
exit;
}
if ( $customResponse['status'] === 'ok' && (int) $customResponse['logged_in_user']['pk'] === (int) $user_id ) {
echo 'Finished, logged in successfully! Run this file again to validate that it works.';
} else {
echo "Probably finished...\n";
//var_dump( $customResponse );
}
} catch ( Exception $ex ) {
echo $ex->getMessage();
}
} else {
//Other stuff.
}
return 'Something went wrong: '.$e->getMessage()."\n";
}