diff --git a/src/Event.php b/src/Event.php index 3a05bb4..7fe2145 100644 --- a/src/Event.php +++ b/src/Event.php @@ -68,9 +68,19 @@ public static function get(Carbon $startDateTime = null, Carbon $endDateTime = n $googleEvents = $googleCalendar->listEvents($startDateTime, $endDateTime, $queryParameters); + $googleEventsList = $googleEvents->getItems(); + + while($googleEvents->getNextPageToken()) { + $queryParameters['pageToken'] = $googleEvents->getNextPageToken(); + + $googleEvents = $googleCalendar->listEvents($startDateTime, $endDateTime, $queryParameters); + + $googleEventsList = array_merge($googleEventsList, $googleEvents->getItems()); + } + $useUserOrder = isset($queryParameters['orderBy']); - return collect($googleEvents) + return collect($googleEventsList) ->map(function (Google_Service_Calendar_Event $event) use ($calendarId) { return static::createFromGoogleCalendarEvent($event, $calendarId); }) diff --git a/src/GoogleCalendar.php b/src/GoogleCalendar.php index 33dda3b..b5978a0 100644 --- a/src/GoogleCalendar.php +++ b/src/GoogleCalendar.php @@ -6,6 +6,7 @@ use DateTime; use Google_Service_Calendar; use Google_Service_Calendar_Event; +use Google_Service_Calendar_Events; class GoogleCalendar { @@ -30,7 +31,7 @@ public function getCalendarId(): string /* * @link https://developers.google.com/google-apps/calendar/v3/reference/events/list */ - public function listEvents(Carbon $startDateTime = null, Carbon $endDateTime = null, array $queryParameters = []): array + public function listEvents(Carbon $startDateTime = null, Carbon $endDateTime = null, array $queryParameters = []): Google_Service_Calendar_Events { $parameters = [ 'singleEvents' => true, @@ -53,8 +54,7 @@ public function listEvents(Carbon $startDateTime = null, Carbon $endDateTime = n return $this ->calendarService ->events - ->listEvents($this->calendarId, $parameters) - ->getItems(); + ->listEvents($this->calendarId, $parameters); } public function getEvent(string $eventId): Google_Service_Calendar_Event