无法重复 API Google 日历 PHP

Can't get recurrence API Google Calendar PHP

我正在尝试通过 PHP 中的 Google 日历 API 获取事件的重现,但它没有显示重现。

以下代码是我使用的代码:

$params = array(
                'orderBy' => 'startTime',
                'singleEvents' => true,
                'timeMin' => date('c'),
        );
        $listarEventos = $service->events->listEvents($calendar_id, $params);
        foreach ($listarEventos->getItems() as $i){
            echo "<pre>";
            echo $i->recurrence;
            print_r($i);
            echo "</pre>";
            echo "<br>";
        }

我正在获取此类对象:

Google_Service_Calendar_Event Object
(
    [collection_key:protected] => recurrence
    [internal_gapi_mappings:protected] => Array
        (
        )

    [anyoneCanAddSelf] => 
    [attendeesType:protected] => Google_Service_Calendar_EventAttendee
    [attendeesDataType:protected] => array
    [attendeesOmitted] => 
    [colorId] => 
    [created] => 2015-06-01T07:34:46.000Z
    [creatorType:protected] => Google_Service_Calendar_EventCreator
    [creatorDataType:protected] => 
    [description] => 
    [endType:protected] => Google_Service_Calendar_EventDateTime
    [endDataType:protected] => 
    [endTimeUnspecified] => 
    [etag] => "286628817348xxxx"
    [extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties
    [extendedPropertiesDataType:protected] => 
    [gadgetType:protected] => Google_Service_Calendar_EventGadget
    [gadgetDataType:protected] => 
    [guestsCanInviteOthers] => 
    [guestsCanModify] => 
    [guestsCanSeeOtherGuests] => 
    [hangoutLink] => 
    [htmlLink] => https://www.google.com/calendar/event?eid=czlqcW9uNmg1aGV0cTBwYXRrcnIxc2dqc3MgcHJ1ZWJhY2FsZW5kYXJpbxxxxxt
    [iCalUID] => s9jqon6h5hetq0patkrr1sgjss@google.com
    [id] => s9jqon6h5hetq0patkrr1sxxxxx
    [kind] => calendar#event
    [location] => Gra
    [locked] => 
    [organizerType:protected] => Google_Service_Calendar_EventOrganizer
    [organizerDataType:protected] => 
    [originalStartTimeType:protected] => Google_Service_Calendar_EventDateTime
    [originalStartTimeDataType:protected] => 
    [privateCopy] => 
    [recurrence] => 
    [recurringEventId] => 
    [remindersType:protected] => Google_Service_Calendar_EventReminders
    [remindersDataType:protected] => 
    [sequence] => 0
    [sourceType:protected] => Google_Service_Calendar_EventSource
    [sourceDataType:protected] => 
    [startType:protected] => Google_Service_Calendar_EventDateTime
    [startDataType:protected] => 
    [status] => confirmed
    [summary] => Prueba recurrencia
    [transparency] => 
    [updated] => 2015-06-01T07:34:46.742Z
    [visibility] => 
    [modelData:protected] => Array
        (
            [creator] => Array
                (
                    [email] => xxxx@gmail.com
                    [displayName] => Prueba Calendario
                    [self] => 1
                )

            [organizer] => Array
                (
                    [email] => xxxxx@gmail.com
                    [displayName] => Prueba Calendario
                    [self] => 1
                )

            [start] => Array
                (
                    [dateTime] => 2015-06-19T03:01:00+02:00
                    [timeZone] => Europe/Madrid
                )

            [end] => Array
                (
                    [dateTime] => 2015-06-19T09:03:00+02:00
                    [timeZone] => Europe/Madrid
                )

            [reminders] => Array
                (
                    [useDefault] => 1
                )

        )

    [processed:protected] => Array
        (
        )

)

不得不说我是用下面的代码存储循环的:

$event->setRecurrence(array('RRULE:FREQ='.$FREQ.';INTERVAL='.$INTERVAL));

而且我已经证明事件是循环的,所以我不知道为什么我不能得到循环。

非常感谢!

如果您使用 'singleEvents' => true,您将不会复发。

文档 (https://developers.google.com/google-apps/calendar/v3/reference/events/list) 说:

singleEvents boolean Whether to expand recurring events into instances and only return single one-off events and instances of recurring events, but not the underlying recurring events themselves. Optional. The default is False.

我已经解决了这个问题。如果你没有得到像这样的事件,你就不会得到重复:

$event = $service->events->get('primary', "recurringEventId");

一旦你有了$event,你就可以使用:

$preevent->recurrence[0]

感谢 Xeron 的回答。