using the googleapis library in dart to update a calendar and display it on a webpage

前端 未结 2 940
孤独总比滥情好
孤独总比滥情好 2021-01-25 07:14

I am new to dart and I have been trying to figure out how to use the googleapis library to update a calendars events, then display the calendar/events on a webpage.

2条回答
  •  逝去的感伤
    2021-01-25 08:07

    Using the following code you can display the events of a calendar associated with the logged account. In this example i used createImplicitBrowserFlow ( see the documentation at https://pub.dartlang.org/packages/googleapis_auth ) with id and key from Google Cloud Console Project.

    import 'dart:html';
    import 'package:googleapis/calendar/v3.dart';
    import 'package:googleapis_auth/auth_browser.dart' as auth;
    
    var id = new auth.ClientId("", "");
    var scopes = [CalendarApi.CalendarScope];
    
      void main() {
    
      auth.createImplicitBrowserFlow(id, scopes).then((auth.BrowserOAuth2Flow flow) {
            flow.clientViaUserConsent().then((auth.AuthClient client) {
    
              var calendar = new CalendarApi(client);
    
                  String adminPanelCalendarId = 'primary';
    
                  var event = calendar.events;
    
                  var events = event.list(adminPanelCalendarId);
    
                  events.then((showEvents) {
                    showEvents.items.forEach((Event ev) { print(ev.summary); });
                    querySelector("#text2").text = showEvents.toString();
                  });      
    
    
              client.close();
              flow.close();
            });
          });
    
    }
    

提交回复
热议问题