2016-07-08 107 views
1

我正在使用Microsoft的示例Django應用程序並試圖從現在開始讀取日曆事件回到1年前。該API請求使用Python請求函數完成:如何爲Outlook日曆API調用插入開始日期和結束日期和時間

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字典插入的startDateTime和endDateTime參數:

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

我仍然得到事件之前,從一年前的轉儲。我在這裏做錯了什麼? query_parameters是插入開始和結束日期和時間的正確位置嗎?

+0

'url'的價值是什麼? –

+0

嗨賈森,網址值是:https://outlook.office.com/api/v2.0/Me/Events –

回答

0

爲了使用startDateTimeendDateTime參數限制日期範圍,您需要在/calendarview端點,而不是/eventsGET/events端點不支持這些參數。

url更改爲https://outlook.office.com/api/v2.0/Me/calendarview並查看您是否獲得了更好的結果。

+0

就是這樣!謝謝傑森,感謝你的幫助。 –

相關問題