2
votes

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()}");
  });

updated pic

Why?

1
What doesn't work? could you included any error messages/logging you are getting?Jonah Williams
The only error given is "bad request 400" and that's in the .catchError method, it's at the bottom of that screenshotSeaRoth
I'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/listJonah Williams
I totally agree - I use that tool a lot -SeaRoth

1 Answers

7
votes

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.