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.

Share:
2,751
SeaRoth
Author by

SeaRoth

Updated on December 04, 2022

Comments

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

    updated pic

    Why?

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