public static function getPaginateMedias($username, $maxId = '') { $hasNextPage = true; $medias = []; $toReturn = ['medias' => $medias, 'maxId' => $maxId, 'hasNextPage' => $hasNextPage]; $response = Request::get(Endpoints::getAccountMediasJsonLink($username, $maxId)); if ($response->code !== 200) { throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.'); } $arr = json_decode($response->raw_body, true); if (!is_array($arr)) { throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.'); } if (count($arr['items']) === 0) { return $toReturn; } foreach ($arr['items'] as $mediaArray) { $medias[] = Media::fromApi($mediaArray); } $maxId = $arr['items'][count($arr['items']) - 1]['id']; $hasNextPage = $arr['more_available']; $toReturn = ['medias' => $medias, 'maxId' => $maxId, 'hasNextPage' => $hasNextPage]; return $toReturn; }