Flutter Google Calendar Api list Events

这一生的挚爱 提交于 2020-06-12 15:23:20

问题


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?


回答1:


According to the Google calendar API the timeMin and timeMax values must follow the RFC3339 date standard.

Internally the calendar applies .toIso8601String() on the DateTimes you pass in. However that does not make them valid RFC3339 dates.

Calling .toUtc() before passing them in will make them a valid RFC3339. You can try it in DartPad togheter with Googles Api explorer and you will see the different responses.

There is probably more ways to make DateTime RFC3339 compliant but this should point you to the error atleast.



来源:https://stackoverflow.com/questions/49724445/flutter-google-calendar-api-list-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!