如何插入 Outlook 日历 API 调用的开始和结束日期和时间



我正在使用Microsoft的示例 Django 应用程序,并尝试从现在开始读取 1 年前的日历事件。API 请求是使用 Python 请求函数完成的:

response = requests.get(url, headers = headers, params = parameters)

标头与标准 API 请求相关:

headers = { 'User-Agent' : 'python_events/1.0',
            'Authorization' : 'Bearer {0}'.format(token),
            'Accept' : 'application/json',
            'X-AnchorMailbox' : user_email }

而且,对于我传递的参数:

  query_parameters = {'$top': '2500',
                      '$select': 'Id,Subject,Start,End',
                      '$orderby': 'Start/DateTime ASC'}

现在,我尝试将开始和结束日期定义为:

  now = datetime.utcnow()
  one_year = now - timedelta(days=365)
  now = now.isoformat()
  one_year = one_year.isoformat()

然后,尝试在同一query_parameters字典中插入开始日期时间和结束日期时间参数:

  query_parameters = {'$top': '2500',
                      '$select': 'Id,Subject,Start,End',
                      '$orderby': 'Start/DateTime ASC',
                      'startDateTime' : one_year,
                      'endDateTime': now
                     }

我仍然收到一年前的事件转储。我在这里做错了什么?query_parameters插入开始和结束日期和时间的正确位置吗?

为了使用 startDateTimeendDateTime 参数来限制日期范围,您需要对/calendarview端点执行GET,而不是/events/events终结点不支持这些参数。

url更改为https://outlook.office.com/api/v2.0/Me/calendarview,看看是否获得更好的结果。

最新更新