我可以将日历事件与 Microsoft Graph API 同步吗?

2024-05-09

我正在使用 Microsoft Graph api 尝试从 Outlook 同步日历事件。我在看本文 https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations#SyncCalendarView关于 Outlook api,建议我添加标头odata.track-changes根据我的要求,我会收到deltaToken,我可以在稍后的请求中使用它来仅获取自上次同步以来已更新或创建的事件。

我已成功获取事件,但我没有取回 deltaToken :/

仅 Outlook api 支持此功能吗?图的响应有Preference-Applied: odata.track-changes,所以它确认了我的标题。这是我的示例请求:

GET /v1.0/me/calendar/calendarView
    ?startDateTime=2016-09-01T00:00:00.0000000
    &endDateTime=2099-01-01T00:00:00.0000000
    HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer XXX
Prefer: odata.track-changes
Prefer: odata.maxpagesize=3  //for testing
Cache-Control: no-cache

我的回复样本:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('')/calendar/calendarView",
  "value": [
    {
      "@odata.etag": "",
      "id": "",
      "createdDateTime": "2016-08-04T14:00:25.8552351Z",
      "lastModifiedDateTime": "2016-08-25T14:43:54.9950828Z",
      "changeKey": "",
      "categories": [
        "Orange category"
      ],
      "originalStartTimeZone": "Eastern Standard Time",
      "originalEndTimeZone": "Eastern Standard Time",
      "responseStatus": {
        "response": "organizer",
        "time": "0001-01-01T00:00:00Z"
      },
      "iCalUId": "",
      "reminderMinutesBeforeStart": 15,
      "isReminderOn": true,
      "hasAttachments": false,
      "subject": "Closing on House",
      "body": {
        "contentType": "html",
        "content": ""
      },
      "bodyPreview": "",
      "importance": "normal",
      "sensitivity": "normal",
      "start": {
        "dateTime": "2016-09-08T19:30:00.0000000",
        "timeZone": "UTC"
      },
      "end": {
        "dateTime": "2016-09-08T21:30:00.0000000",
        "timeZone": "UTC"
      },
      "location": {
        "displayName": "245 E Main St",
        "address": {
          "street": "245 E Main St",
          "city": "Somewhere",
          "state": "NY",
          "countryOrRegion": "United States",
          "postalCode": ""
        }
      },
      "isAllDay": false,
      "isCancelled": false,
      "isOrganizer": true,
      "recurrence": null,
      "responseRequested": true,
      "seriesMasterId": null,
      "showAs": "busy",
      "type": "singleInstance",
      "attendees": [],
      "organizer": {
        "emailAddress": {
          "name": "",
          "address": ""
        }
      },
      "webLink": "https://outlook.office365.com/owa/?ItemID="
    },
    {
      "@odata.etag": "",
      "id": "",
      "createdDateTime": "2016-08-19T18:02:39.0607411Z",
      "lastModifiedDateTime": "2016-08-19T18:04:10.548447Z",
      "changeKey": "",
      "categories": [
        "Green category"
      ],
      "originalStartTimeZone": "UTC",
      "originalEndTimeZone": "UTC",
      "responseStatus": {
        "response": "organizer",
        "time": "0001-01-01T00:00:00Z"
      },
      "iCalUId": "",
      "reminderMinutesBeforeStart": 15,
      "isReminderOn": true,
      "hasAttachments": false,
      "subject": "Moving (off work)",
      "body": {
        "contentType": "html",
        "content": ""
      },
      "bodyPreview": "",
      "importance": "normal",
      "sensitivity": "normal",
      "start": {
        "dateTime": "2016-09-10T00:00:00.0000000",
        "timeZone": "UTC"
      },
      "end": {
        "dateTime": "2016-09-13T00:00:00.0000000",
        "timeZone": "UTC"
      },
      "location": {
        "displayName": "",
        "address": {}
      },
      "isAllDay": true,
      "isCancelled": false,
      "isOrganizer": true,
      "recurrence": null,
      "responseRequested": true,
      "seriesMasterId": null,
      "showAs": "oof",
      "type": "singleInstance",
      "attendees": [],
      "organizer": {
        "emailAddress": {
          "name": "",
          "address": ""
        }
      },
      "webLink": "https://outlook.office365.com/owa/?ItemID="
    },
    {
      "@odata.etag": "",
      "id": "",
      "createdDateTime": "2016-09-13T19:05:20.8438647Z",
      "lastModifiedDateTime": "2016-09-13T19:05:22.1899702Z",
      "changeKey": "",
      "categories": [],
      "originalStartTimeZone": "America/New_York",
      "originalEndTimeZone": "America/New_York",
      "responseStatus": {
        "response": "organizer",
        "time": "0001-01-01T00:00:00Z"
      },
      "iCalUId": "",
      "reminderMinutesBeforeStart": 15,
      "isReminderOn": true,
      "hasAttachments": false,
      "subject": "Coffee Break",
      "body": {
        "contentType": "html",
        "content": ""
      },
      "bodyPreview": "",
      "importance": "normal",
      "sensitivity": "normal",
      "start": {
        "dateTime": "2016-09-15T20:15:00.0000000",
        "timeZone": "UTC"
      },
      "end": {
        "dateTime": "2016-09-15T21:15:00.0000000",
        "timeZone": "UTC"
      },
      "location": {
        "displayName": "",
        "address": {}
      },
      "isAllDay": false,
      "isCancelled": false,
      "isOrganizer": true,
      "recurrence": null,
      "responseRequested": true,
      "seriesMasterId": null,
      "showAs": "busy",
      "type": "singleInstance",
      "attendees": [],
      "organizer": {
        "emailAddress": {
          "name": "",
          "address": ""
        }
      },
      "webLink": "https://outlook.office365.com/owa/?ItemID="
    }
  ]
}

我删除了所有我认为可能稍微敏感的内容。最终,我的 Laravel 应用程序尝试同步 4 个月前开始的事件,并永远持续到未来。

如果有更有效/更好的方法来做到这一点,我愿意接受建议。如果重要的话,这些结果是由 Postman 生成的。对此的任何帮助或澄清表示赞赏。


我最终使用了官方数据过滤器 http://www.odata.org/getting-started/basic-tutorial/像这样:

https://graph.microsoft.com/beta/me/calendar/calendarView?startDateTime=2016-05-01T00:00:00Z&endDateTime=2099-01-01T00:00:00Z&$filter=type eq 'singleInstance' and lastModifiedDateTime eq '2016-09-20T07:30:00+00:00'

这将获取之间安排的所有日历事件2016-05-01T00:00:00Z (May 1st, 2016, midnight, UTC and 2099-01-01T00:00:00Z (January 1st, 2099, midnight, UTC)其中事件类型是singleInstance(不是重复发生的事件)和lastModifiedDateTime是在上次同步之后(在本例中,2016-09-20T07:30:00+00:00).

这样做有一些陷阱:

  1. 显然,这不是 url 编码的。你需要这样做。
  2. 确保lastModifiedDateTime 示例中的 + 已正确编码为%2B,否则 Graph API 会将其视为空格并拒绝它。
  3. 如果不过滤掉重复事件,您将获得从现在到 2099 年的每个重复事件。这就是获取列表的本质calendarViews相对于events.

如果我能再次这样做,我可能会返回并进行完整的日历同步,这是 Graph 支持的(我相信)。我只是不想同步整个日历,只想同步一个日期范围,但这似乎是注定要失败的努力。

但尽管没有重复发生的事件,它仍然有效。

UPDATE

我最终放弃了这个实现,主要是因为我在维护数据同步完整性、缺乏重复事件等方面遇到了持续的陷阱。相反,我提取了日历事件实时,并维护缓存。只是一些建议,以防其他人遇到我的情况。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我可以将日历事件与 Microsoft Graph API 同步吗? 的相关文章

随机推荐

  • 条件顺序仅在 init AngularJS 上执行

    如何在视图初始化时仅运行 orderBy 过滤器一次 我不希望我的列表在运行时被重新排序 li li 使用 orderBy 作为控制器中的过滤器 app controller DemoCtrl scope filter function s
  • 在多面图中用 N 注释 x 轴

    我正在尝试生成一些按治疗条件和访问次数细分的数字结果的箱线图 每个框中的观察次数都放在图下方 并且也标记了访问次数 这里有一些虚假数据可以用来说明 我举了两个我尝试过但不太有效的例子 library ggplot2 library plyr
  • 我的 apk 文件在模拟器中的位置

    我在 eclipse android 中编写了一个小程序 现在我安装并运行我的程序 它是一个 apk 现在我想知道我的 apk 文件在哪里 我什至想将它 拉 到我的系统中 是否可以 如果是这样请帮助我 如果您只想将 apk 安装在手机或类似
  • 从有符号字符转换为无符号字符然后再转换回来?

    我正在使用 JNI 并有一个 jbyte 类型的数组 其中 jbyte 表示为有符号字符 即范围从 128 到 127 jbyte 表示图像像素 对于图像处理 我们通常希望像素分量的范围为0到255 因此 我想将jbyte值转换为0到255
  • Jinja2中获取请求参数

    如何检索请求参数a在 Jinja2 模板中 http foo bar a 1 我这个答案有点晚了 但其他解决方案并没有真正考虑到您对 Flask 的使用 事实上 您将 Flask 与 Jinja2 一起使用 这使得您的情况与其他框架有点不同
  • 如果所有类不在同一个包中,Spring @autowired 不起作用

    我有四个包裹 com spring org Files HomeController java com spring org dao Files SubscriberDao java SubscriberDaoImpl java com s
  • RecyclerView 适配器的 Kotlin 泛型

    我正在尝试编写一个通用的 recyclerview 适配器 我找到了几个例子 然而 仍然无法弄清楚如何实现通用适配器 我写的代码是 open abstract class BaseAdapter
  • 如何设置 CMake 与 clang 交叉编译 Windows 上的 ARM 嵌入式系统?

    我正在尝试生成 Ninja makefile 以使用 Clang 为 ARM Cortex A5 CPU 交叉编译 C 项目 我为 CMake 创建了一个工具链文件 但似乎存在错误或缺少一些我无法找到的东西 当使用下面的工具链文件调用 CM
  • UITableView 自动调整行大小约束在 iPhone 6Plus 上神秘破坏

    我有一个自定义的 UITableViewCell 它有一个缩略图和一堆文本 行高配置为使用自动计算 tableView estimatedRowHeight 129 tableView rowHeight UITableViewAutoma
  • 为 ggplot 定义新的尺度轴变换

    我正在尝试创建一个squared使用 y 轴变换scales trans new但遇到错误 MWE data data frame x 1 10 y runif 10 z rnorm 10 10 library ggplot2 ggplot
  • 获取 Google Cloud 服务帐户的开发者密钥

    我已经启用了XML API https cloud google com storage docs interoperability并分配了一些开发者密钥 https cloud google com storage docs migrat
  • 为什么某些 Web.config 转换标记化为 SetParameters.xml,而其他则不然?

    我最近在 VS2010 中使用配置转换相当多 但我很困惑为什么有些转换直接应用于包中的 Web config 而其他转换则针对 SetParameters xml 中的令牌存储 然后在发布时应用 例如 采用具有以下连接字符串和应用程序设置的
  • JQuery 表单提交不发送帖子

    我在使用 JQuery 提交表单时遇到问题 当按下提交按钮时 表单会正确提交 但是当我尝试使用时 somebutton click function form myForm submit 我还尝试从 Chrome 控制台调用表单提交 表单未
  • 如何让你的精灵在pygame中跳跃

    目前我已经制作了一个平台游戏 可以左右移动我的角色 他从地上开始 关于如何让他跳的任何想法 因为我不明白 目前 如果我按住向上键 我的玩家精灵将连续向上移动 或者如果我按下它 我的玩家精灵将向上移动并保持向上 我想找个办法远离他 让我重新跌
  • iOS:启动图像多语言

    我有一个多语言应用程序 我的问题是启动图像 根据设备的语言使用启动图像的方法是什么 有什么东西在info plist file 解决方案是像项目中的任何其他资源一样本地化 Default png 从 Xcode 的项目列表中选择 Defau
  • 如何在SpringBootTest中向Autowired testRestTemplate添加基本身份验证;春季启动 1.4

    我在 Spring Boot 1 4 之前的 OAuth 集成测试如下 更新只是为了不使用已弃用的功能 RunWith SpringRunner class SpringBootTest classes ApplicationConfigu
  • 如何正确使用Google Calendar API Events.Insert命令?

    所以我一直使用REST方法来调用Google的API 我需要将事件插入到我拥有 ID 的特定日历中 这是我发送的 POST 请求 地址 https www googleapis com calendar v3 calendars https
  • jQuery 查找 id 以total 开头的所有li

    我有以下内容 但只想循环 lines 中 id 以total 开头的行 lines li each function 有任何想法吗 Lee lines li id total each function
  • 如何检查 Gmail 标签是否有嵌套子标签?

    使用Google Apps脚本 是否有一个功能可以检查Gmail标签是否有嵌套子标签 如果标签有一个或多个子标签 我想将它们从代码序列中排除 没有直接的方法可以从 父 标签获取标签 但是使用简单的方法来获取标签非常简单getUserLabe
  • 我可以将日历事件与 Microsoft Graph API 同步吗?

    我正在使用 Microsoft Graph api 尝试从 Outlook 同步日历事件 我在看本文 https msdn microsoft com en us office office365 api calendar rest ope