public static function searchAccountsByUsername($username)
{
$response = Request::get(Endpoints::getGeneralSearchJsonLink($username));
if ($response->code === 404) {
throw new InstagramNotFoundException('Account with given username does not exist.');
}
if ($response->code !== 200) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.');
}
$jsonResponse = json_decode($response->raw_body, true);
if (!isset($jsonResponse['status']) || $jsonResponse['status'] != 'ok') {
throw new InstagramException('Response code is not equal 200. Something went wrong. Please report issue.');
}
if (!isset($jsonResponse['users']) || count($jsonResponse['users']) == 0) {
return [];
}
$accounts = [];
foreach ($jsonResponse['users'] as $jsonAccount) {
$accounts[] = Account::fromSearchPage($jsonAccount['user']);
}
return $accounts;
}