调用 Office365 API 同步事件,节流
Calls to Office365 API to synchronize events, throttling
我正在尝试将一些事件从 Outlook 同步到我的本地数据库,我调用 API 如下:
$url = 'https://outlook.office365.com/api/v2.0/users/' . $this->user . '/CalendarView/'
. '?startDateTime=' . $start_datetime
. '&endDateTime=' . $end_datetime
这为我提供了两个特定日期之间来自 Outlook 的所有事件。
然后我使用下面的代码保存所有这些事件。它的问题是它 returns 一次只有 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
参数实际上应该是事件总数。
正确的查询参数是 $top
而不是 top
。注意那里的$
。
5.1.5 System Query Options $top and $skip
The $top system query option requests the number of items in the queried collection to be included in the result. The $skip query option requests the number of items in the queried collection that are to be skipped and not included in the result. A client can request a particular page of items by combining $top and $skip.
The semantics of $top and $skip are covered in the [OData-Protocol] document. The [OData-ABNF] top and skip syntax rules define the formal grammar of the $top and $skip query options respectively.
我正在尝试将一些事件从 Outlook 同步到我的本地数据库,我调用 API 如下:
$url = 'https://outlook.office365.com/api/v2.0/users/' . $this->user . '/CalendarView/'
. '?startDateTime=' . $start_datetime
. '&endDateTime=' . $end_datetime
这为我提供了两个特定日期之间来自 Outlook 的所有事件。
然后我使用下面的代码保存所有这些事件。它的问题是它 returns 一次只有 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
参数实际上应该是事件总数。
正确的查询参数是 $top
而不是 top
。注意那里的$
。
5.1.5 System Query Options $top and $skip The $top system query option requests the number of items in the queried collection to be included in the result. The $skip query option requests the number of items in the queried collection that are to be skipped and not included in the result. A client can request a particular page of items by combining $top and $skip. The semantics of $top and $skip are covered in the [OData-Protocol] document. The [OData-ABNF] top and skip syntax rules define the formal grammar of the $top and $skip query options respectively.