简体   繁体   English

无法获得递归API Google Calendar PHP

[英]Can't get recurrence API Google Calendar PHP

I am trying to get the recurrence of an event with the Google Calendar API in PHP, and it doesn't show me the recurrence. 我正在尝试使用PHP中的Google Calendar API来使事件重现,但并没有显示重现。

The following code is the code I'm using: 以下代码是我正在使用的代码:

$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>";
        }

And I am obtaining this type of objects: 我正在获得这种类型的对象:

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
        (
        )

)

I have to say that I store the recurrence with the following code: 我不得不说我用以下代码存储重复:

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

And I have proved that the event is recurrent, so I don´t know why I can't get the recurrence. 而且我已经证明该事件是重复发生的,所以我不知道为什么我无法重现。

Thanks a lot! 非常感谢!

You won't get recurrence if you're using 'singleEvents' => true . 如果您使用'singleEvents' => true则不会复发。

Documentation ( https://developers.google.com/google-apps/calendar/v3/reference/events/list ) says: 文档( 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. singleEvents boolean是否将重复事件扩展为实例,并且仅返回单个一次性事件和重复事件的实例,而不返回基础重复事件本身。 Optional. 可选的。 The default is False. 默认值为False。

I have solved the question. 我已经解决了这个问题。 You won't get the recurrence if you doesn't get the event with something like this: 如果没有以下事件,则不会重复发生:

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

Once you have $event, you can use: 拥有$ event后,您可以使用:

$preevent->recurrence[0]

Thanks to Xeron for the answer. 感谢Xeron的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM