Im using mgp25 private instagram api for my needs.
From time to time Im getting ChallengeRequired error, which Im resolving like below:
/**
* Резолвим челлендж
*
* @param array $data
* @return bool
* @throws UserRegistrationException
*/
public function resolveChallenge(array $data): bool
{
$this->client = $this->getInstagramClient();
$this->client->changeUser($data['login'], $data['password']);
$customResponse = $this->client->request($data['url'])->setNeedsAuth(false)->addPost("security_code", $data['code'])->getDecodedResponse();
if (!is_array($customResponse)) {
throw new Exception('Не удалось подтвердить вход');
}
$this->isMakeLogin = true;
// Зашли
if ($customResponse['status'] == "ok" && isset($customResponse['logged_in_user']) && (int)$customResponse['logged_in_user']['pk'] === (int)explode('/', $data['url'])[1]) {
return $this->registerUserIfNotExists($data['login'], $data['password']);
}
// mgp25
if ($customResponse['status'] === 'ok' && $customResponse['action'] === 'close') {
return $this->registerUserIfNotExists($data['login'], $data['password']);
}
throw new Exception(isset($customResponse['message']) ? $customResponse['message'] : json_encode($customResponse));
}
After challenge is resolved Im calling function:
return $this->registerUserIfNotExists($data['login'], $data['password']);
Which calls login API method and requests some account data, and, sometimes Im getting ChallengeRequired error once more(loop).
What is the reason?