Flutter Google Calendar Api list Events
2,751
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.
Author by
SeaRoth
Updated on December 04, 2022Comments
-
SeaRoth over 1 year
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?
-
Jonah Williams about 6 yearsWhat doesn't work? could you included any error messages/logging you are getting?
-
SeaRoth about 6 yearsThe only error given is "bad request 400" and that's in the .catchError method, it's at the bottom of that screenshot
-
Jonah Williams about 6 yearsI'm not sure what is wrong in this case. I would try using the explorer tool to try and narrow down the source of the problem developers.google.com/calendar/v3/reference/events/list
-
SeaRoth about 6 yearsI totally agree - I use that tool a lot -
-