You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法获取重复事件(Recurring Event)的所有实例问题咨询

获取重复事件所有实例的解决方法

调用Microsoft Graph获取重复事件实例时默认仅返回10条结果,这是接口的默认分页限制导致的。要获取指定时间范围内的所有实例,需要通过分页遍历逻辑来实现:

实现步骤

  • 发起首次请求获取第一页实例
  • 检查是否存在下一页请求链接,若存在则循环获取后续页面的结果
  • 将所有页面的实例合并到一个集合中

示例代码(C#)

var queryOptions = new List<QueryOption>()
{
    new QueryOption("startDateTime", "2022-10-27T00:00:00"),
    new QueryOption("endDateTime", "2023-01-06T00:00:00")
};

var allInstances = new List<Event>();
var currentPage = await graphClient.Users["{user-id}"].Events["{event-id}"].Instances.Request(queryOptions).GetAsync();

// 添加第一页的实例
allInstances.AddRange(currentPage.CurrentPage);

// 遍历所有分页,直到没有下一页
while (currentPage.NextPageRequest != null)
{
    currentPage = await currentPage.NextPageRequest.GetAsync();
    allInstances.AddRange(currentPage.CurrentPage);
}

// allInstances 集合中现在包含了该重复事件的所有实例

补充说明

  • 该逻辑适用于所有存在分页限制的Microsoft Graph列表接口,不仅限于事件实例查询
  • 确保startDateTime和endDateTime覆盖了重复事件的所有时间范围,避免遗漏实例

内容的提问来源于stack exchange,提问作者Tomo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 15:20:31