代码之家  ›  专栏  ›  技术社区  ›  Serge

Google日历API返回日期范围之外的事件

  •  0
  • Serge  · 技术社区  · 14 年前

    我正试着从今天开始选择接下来两周的活动。

    • 10月8日
    • 10月20日

            CalendarService calService = new CalendarService(calendarAppName);
            calService.setUserCredentials(username, password);
    
            CalendarQuery calQuery = new CalendarQuery();
            calQuery.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed calFeed = (CalendarFeed)calService.Query(calQuery);
    
            var activeCalendar = calFeed.Entries.Where(x => x.Title.Text == calendarName).FirstOrDefault();
            if (activeCalendar != null)
            {
               EventQuery evtQuery = new EventQuery(GetCalendarFeed(activeCalendar));
               evtQuery.StartDate = DateTime.Now.AddDays(-1);
               evtQuery.EndDate = DateTime.Now.AddDays(14);
               evtQuery.FutureEvents = false;
    
               EventFeed evtFeed = calService.Query(evtQuery);
            }
    
            ...
    
            private static string GetCalendarFeed(AtomEntry calendarEntry)
            {
               string feedstring = calendarEntry.Id.AbsoluteUri.Substring(63);
               return string.Format("http://www.google.com/calendar/feeds/{0}/private/full", feedstring);
            }
    

    有人发现什么不对劲吗?

    编辑: 结果发现StartTime/EndTime工作正常。但我真的不明白有什么不同,我似乎在文件里什么也找不到。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Sergey Sergey    14 年前

    我只需要用StartTime/EndTime来代替。仍然不知道何时使用StartDate和EndDate,但这确实解决了我的问题。