重复规则无效?
Invalid recurrence rule?
这是我使用 cURL
传递给 Google 日历 API 的负载:
["start"]=>
string(25) "2019-07-01T00:00:00+08:00"
["end"]=>
string(25) "2019-07-16T00:00:00+08:00"
["title"]=>
string(20) "Google Sync Weekly 4"
["description"]=>
string(20) "Google Sync Weekly 4"
["recurrence"]=>
string(44) "RRULE=WEEKLY;UNTIL=2019-07-16T00:00:00+08:00"
在我的 new_event.php
中,我处理此负载的地方:
$event = new Google_Service_Calendar_Event(array(
'summary' => $event['title'],
'location' => !empty($event['location']) ? $event['location'] : '',
'description' => $event['description'],
'start' => array(
'dateTime' => $event['start'],
'timeZone' => 'Asia/Taipei',
),
'end' => array(
'dateTime' => $event['end'],
'timeZone' => 'Asia/Taipei',
),
'recurrence' => !empty($event['recurrence']) ? [$event['recurrence']] : [],
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
这是值:
["recurrence"]=>
array(1) {
[0]=>
string(44) "RRULE=WEEKLY;UNTIL=2019-07-16T00:00:00+08:00"
}
我想不通我哪里错了。有什么提示吗?
以下按预期工作:
$event = [
'start' => "2019-07-01T00:00:00+08:00",
'end' => "2019-07-16T00:00:00+08:00",
'title' => "Google Sync Weekly 4",
'description' => "Google Sync Weekly 4",
'recurrence' => "RRULE:FREQ=WEEKLY;UNTIL=20190716T000000Z",
];
$event = new Google_Service_Calendar_Event(array(
'summary' => $event['title'],
'location' => !empty($event['location']) ? $event['location'] : '',
'description' => $event['description'],
'start' => array(
'dateTime' => $event['start'],
'timeZone' => 'Asia/Taipei',
),
'end' => array(
'dateTime' => $event['end'],
'timeZone' => 'Asia/Taipei',
),
'recurrence' => !empty($event['recurrence']) ? [$event['recurrence']] : [],
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$service = new Google_Service_Calendar($client);
$service->events->insert('primary', $event);
如错误消息所示,问题是您的重复规则格式不正确。规则应以 RRULE:
为前缀,并且必须遵循 RFC 5545. Pay close attention to the sections regarding timestamps and timezones. A basic example of a properly formatted rule may be found in the "Creating recurring events" code snippet in the API documentation site.
中规定的规则
您还可以从日历 UI 创建定期并通过 API 获取它以获取其他更有针对性的示例。
这是我使用 cURL
传递给 Google 日历 API 的负载:
["start"]=>
string(25) "2019-07-01T00:00:00+08:00"
["end"]=>
string(25) "2019-07-16T00:00:00+08:00"
["title"]=>
string(20) "Google Sync Weekly 4"
["description"]=>
string(20) "Google Sync Weekly 4"
["recurrence"]=>
string(44) "RRULE=WEEKLY;UNTIL=2019-07-16T00:00:00+08:00"
在我的 new_event.php
中,我处理此负载的地方:
$event = new Google_Service_Calendar_Event(array(
'summary' => $event['title'],
'location' => !empty($event['location']) ? $event['location'] : '',
'description' => $event['description'],
'start' => array(
'dateTime' => $event['start'],
'timeZone' => 'Asia/Taipei',
),
'end' => array(
'dateTime' => $event['end'],
'timeZone' => 'Asia/Taipei',
),
'recurrence' => !empty($event['recurrence']) ? [$event['recurrence']] : [],
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
这是值:
["recurrence"]=>
array(1) {
[0]=>
string(44) "RRULE=WEEKLY;UNTIL=2019-07-16T00:00:00+08:00"
}
我想不通我哪里错了。有什么提示吗?
以下按预期工作:
$event = [
'start' => "2019-07-01T00:00:00+08:00",
'end' => "2019-07-16T00:00:00+08:00",
'title' => "Google Sync Weekly 4",
'description' => "Google Sync Weekly 4",
'recurrence' => "RRULE:FREQ=WEEKLY;UNTIL=20190716T000000Z",
];
$event = new Google_Service_Calendar_Event(array(
'summary' => $event['title'],
'location' => !empty($event['location']) ? $event['location'] : '',
'description' => $event['description'],
'start' => array(
'dateTime' => $event['start'],
'timeZone' => 'Asia/Taipei',
),
'end' => array(
'dateTime' => $event['end'],
'timeZone' => 'Asia/Taipei',
),
'recurrence' => !empty($event['recurrence']) ? [$event['recurrence']] : [],
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$service = new Google_Service_Calendar($client);
$service->events->insert('primary', $event);
如错误消息所示,问题是您的重复规则格式不正确。规则应以 RRULE:
为前缀,并且必须遵循 RFC 5545. Pay close attention to the sections regarding timestamps and timezones. A basic example of a properly formatted rule may be found in the "Creating recurring events" code snippet in the API documentation site.
您还可以从日历 UI 创建定期并通过 API 获取它以获取其他更有针对性的示例。