简体   繁体   English

调用Office365 API以同步事件,限制

[英]Calls to Office365 API to synchronize events, throttling

I am trying to synchronize a few events from Outlook to my local DB and I call the API as below: 我试图将一些事件从Outlook同步到我的本地数据库,并按如下所示调用API:

$url = 'https://outlook.office365.com/api/v2.0/users/' . $this->user . '/CalendarView/'
    . '?startDateTime=' . $start_datetime
    . '&endDateTime=' . $end_datetime

This gives me all the events from Outlook between two specific dates. 这给了我两个特定日期之间来自Outlook的所有事件。

Then I go and save all this events using the code below. 然后,我使用下面的代码保存所有这些事件。 The problem with it is that it returns only 10 events at a time. 它的问题在于它一次只返回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;

I tried then to call the API like below, setting the top parameter to 10, but I end up with many empty events. 然后,我尝试像下面这样调用API,将top参数设置为10,但最终出现许多空事件。

$url = 'https://outlook.office365.com/api/v2.0/users/' . $this->user . '/CalendarView/'
    . '?startDateTime=' . $start_datetime
    . '&endDateTime=' . $end_datetime
     .'&top=100'

I am trying to avoid making more than 60 calls per minute. 我试图避免每分钟拨打超过60个电话。 Is there any way to first get the number of events between two dates and then retrieve all of them, so the top parameter should actually be the total number of events. 有什么方法可以首先获取两个日期之间的事件数,然后再检索所有事件,因此top参数实际上应该是事件的总数。

The correct query parameter is $top and not top . 正确的查询参数是$top而不是top Notice $ in there. 注意其中的$

http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752362 http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete。 HTML#_Toc453752362

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. 5.1.5系统查询选项$ top和$ skip $ top系统查询选项请求查询的集合中要包含在结果中的项目数。 The $skip query option requests the number of items in the queried collection that are to be skipped and not included in the result. $ skip查询选项请求查询集合中要跳过但不包含在结果中的项目数。 A client can request a particular page of items by combining $top and $skip. 客户可以通过组合$ top和$ skip来请求特定页面的项目。 The semantics of $top and $skip are covered in the [OData-Protocol] document. $ top和$ skip的语义在[OData-Protocol]文档中介绍。 The [OData-ABNF] top and skip syntax rules define the formal grammar of the $top and $skip query options respectively. [OData-ABNF] top和skip语法规则分别定义$ top和$ skip查询选项的形式语法。

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

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