我正在尝试将一些事件从 Outlook 同步到我的本地数据库,我调用 API 如下:
$url = 'https://outlook.office365.com/api/v2.0/users/' . $this->user . '/CalendarView/'
. '?startDateTime=' . $start_datetime
. '&endDateTime=' . $end_datetime
这为我提供了两个特定日期之间来自 Outlook 的所有事件。
然后我去使用下面的代码保存所有这些事件。它的问题是它一次只返回 10 个事件。
$http = new \Http_Curl();
$http->set_headers( $this->get_headers() );
$response = $http->get( $url );
$data = array();
$continue = true;
while ( $continue ) {
if ( isset($response->value) ) {
$arr = array();
foreach ( $response->value as $event ) {
$arr[] = $event;
}
$data = array_merge( $data, $arr );
}
$property = '@odata.nextLink';
if ( isset( $response->$property ) ) {
$url = $response->$property;
$response = $http->get( $url );
} else {
$continue = false;
}
}
unset( $http );
return $data;
然后我尝试像下面那样调用 API,将 top 参数设置为 10,但我最终得到了许多空事件。
$url = 'https://outlook.office365.com/api/v2.0/users/' . $this->user . '/CalendarView/'
. '?startDateTime=' . $start_datetime
. '&endDateTime=' . $end_datetime
.'&top=100'
我试图避免每分钟拨打超过 60 个电话。有什么办法可以先获取两个日期之间的事件数,然后再全部取回,所以top
参数其实应该是事件的总数。