简体   繁体   English

Flutter Google Calendar Api列表活动

[英]Flutter Google Calendar Api list Events

Flutter, Google Calendar API v3 https://pub.dartlang.org/packages/googleapis Flutter,Google Calendar API v3 https://pub.dartlang.org/packages/googleapis

Works: 作品:

  Future<List<Event>> getEvents() =>
  calendarApi.events.list("primary",
  )
  .then((Events events){
    return events.items;
  }).catchError((e){
    print("error encountered");
    print("${e.toString()}");
  });

Doesn't work: 不起作用:

DateTime start = new DateTime.now().subtract(new Duration(days: 10));
DateTime end = new DateTime.now().add(new Duration(days: 10));
..
  Future<List<Event>> getEvents() =>
  calendarApi.events.list("primary",
    timeMin: start,
    timeMax: end,
  )
  .then((Events events){
    return events.items;
  }).catchError((e){
    print("error encountered");
    print("${e.toString()}");
  });

更新的图片

Why? 为什么?

According to the Google calendar API the timeMin and timeMax values must follow the RFC3339 date standard. 根据Google日历API,timeMin和timeMax值必须遵循RFC3339日期标准。

Internally the calendar applies .toIso8601String() on the DateTimes you pass in. However that does not make them valid RFC3339 dates. 在内部,日历在您传入的DateTimes上应用.toIso8601String() 。但是,这不会使它们成为有效的RFC3339日期。

Calling .toUtc() before passing them in will make them a valid RFC3339. 在传递它们之前调用.toUtc()将使它们成为有效的RFC3339。 You can try it in DartPad togheter with Googles Api explorer and you will see the different responses. 您可以使用Google的Api ExplorerDartPad Togheter中尝试一下, 然后会看到不同的响应。

There is probably more ways to make DateTime RFC3339 compliant but this should point you to the error atleast. 可能有更多方法可以使DateTime符合RFC3339,但这应将您至少指向错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM