#!/usr/bin/env perl use warnings; use 5.020; use open ':std',':locale'; use Net::Google::DataAPI::Auth::OAuth2; use Net::OAuth2::AccessToken; use Config::General; use Net::Google::CalendarV3; use POSIX 'strftime'; use Data::Printer; sub Net::Google::CalendarV3::get_all_calendars { my ($self) = @_; my $res = $self->_service->get('/users/me/calendarList', { } ); die $res->error unless $res->success; $self->calendars($res->res->{items}); } my $config_file = Config::General->new('google-to-text.conf'); my %config = $config_file->getall; my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new( client_id => $config{oauth2}->{client_id}, client_secret => $config{oauth2}->{client_secret}, scope => ['https://www.googleapis.com/auth/calendar.readonly'], ); my $token = Net::OAuth2::AccessToken->session_thaw( $config{oauth2}->{token}, profile => $oauth2->oauth2_webserver, ); my $gcal = Net::Google::CalendarV3->new({ oauth2_access_token => $token->access_token, }); $gcal->get_all_calendars(); for my $calendar (@{$gcal->calendars}) { say sprintf 'Calendar %s (%s / %s)', $calendar->id,$calendar->summary,$calendar->description//''; $gcal->set_calendar($calendar); for my $event ($gcal->get_events( timeMin => strftime('%FT%TZ',gmtime), timeMax => strftime('%FT%TZ',gmtime(time+86400*7)), orderBy => 'startTime', singleEvents => 'True', )) { say sprintf " > %s %s - %s\n >> %s\n", $event->summary, ($event->start->get)[0],($event->end->get)[0], $event->description//''; } }