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

前端 未结 2 937
孤独总比滥情好
孤独总比滥情好 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:02

    What you might be looking for is the hybrid flow. This produces two items

    • access credentials (for client side API access)
    • authorization code (for server side API access using the user credentials)

    From the documentation:

    Use case: A web application might want to get consent for accessing data on behalf of a user. The client part is a dynamic webapp which wants to open a popup which asks the user for consent. The webapp might want to use the credentials to make API calls, but the server may want to have offline access to user data as well.

    The page Google+ Sign-In for server-side apps describes how this flow works.

    0 讨论(0)
  • 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("<yourID>", "<yourKey>");
    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();
            });
          });
    
    }
    
    0 讨论(0)
提交回复
热议问题