无效的重复规则?

时间:2019-08-05 04:20:11

标签: php curl google-calendar-api google-api-php-client

这是我使用cURL传递给Google Calendar 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"
  }

我不知道我在这里出了什么问题。有提示吗?

1 个答案:

答案 0 :(得分:0)

以下按预期工作:

$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中列出的规则。请密切注意有关时间戳和时区的部分。在API documentation site的“创建重复发生的事件”代码段中可以找到格式正确的规则的基本示例。

您还可以从Calendar UI创建重复记录,并通过API获取其他定制的示例。