1- using GoogleApis . Blazor . Auth ;
1+ using GoogleApis . Blazor . Auth ;
22using GoogleApis . Blazor . Extensions ;
33using GoogleApis . Blazor . Models ;
44using Microsoft . AspNetCore . Components ;
@@ -94,7 +94,7 @@ public async Task<GoogleCalendarListRoot> GetCalendars(int maxResults = 250, boo
9494 return model ;
9595 }
9696
97- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
97+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
9898 return await GetCalendars ( ) ;
9999 }
100100
@@ -117,7 +117,7 @@ public async Task<GoogleCalendarListModel> GetCalendarById(string calendarId, bo
117117 return model ;
118118 }
119119
120- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
120+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
121121 return await GetCalendarById ( calendarId ) ;
122122 }
123123
@@ -179,7 +179,7 @@ public async Task<GoogleCalendarModel> AddCalendar(GoogleCalendarListModel googl
179179 return model ;
180180 }
181181
182- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
182+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
183183 return await AddCalendar ( googleCalendarListModel ) ;
184184 }
185185
@@ -209,7 +209,7 @@ public async Task<GoogleCalendarModel> UpdateCalendar(string calendarId, GoogleC
209209 return model ;
210210 }
211211
212- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
212+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
213213 return await UpdateCalendar ( calendarId , googleCalendarListModel ) ;
214214 }
215215
@@ -234,7 +234,7 @@ public async Task DeleteCalendar(string calendarId, bool forceAccessToken = fals
234234 return ;
235235 }
236236
237- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
237+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
238238 await DeleteCalendar ( calendarId ) ;
239239 }
240240
@@ -260,7 +260,7 @@ public async Task ClearCalendar(string calendarId, bool forceAccessToken = false
260260 return ;
261261 }
262262
263- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
263+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
264264 await ClearCalendar ( calendarId ) ;
265265 }
266266
@@ -276,12 +276,19 @@ public async Task ClearCalendar(string calendarId, bool forceAccessToken = false
276276 /// <param name="timeMin"></param>
277277 /// <param name="timeMax"></param>
278278 /// <param name="maxResults">Select how many items to return. Max is 2500.</param>
279+ /// <param name="timeZone">Time zone used in the response. Optional. The default is the time zone of the calendar.</param>
279280 /// <param name="forceAccessToken">If true and access token expired, it automatically calls for new access token with refresh token.</param>
280281 /// <returns></returns>
281- public async Task < GoogleCalendarEventRoot > GetEvents ( DateTime timeMin , DateTime timeMax , string calendarId , int maxResults = 2500 , bool forceAccessToken = false )
282+ public async Task < GoogleCalendarEventRoot > GetEvents ( DateTime timeMin , DateTime timeMax , string calendarId , int maxResults = 2500 , string timeZone = null , bool forceAccessToken = false )
282283 {
283284 var client = HttpClientFactory . CreateClient ( ) ;
284- var result = await client . GetAsync ( $ "https://www.googleapis.com/calendar/v3/calendars/{ calendarId } /events?access_token={ _accessToken } &maxResults={ maxResults . ToString ( ) } ") ;
285+ var uri = $ "https://www.googleapis.com/calendar/v3/calendars/{ calendarId } /events?access_token={ _accessToken } &maxResults={ maxResults . ToString ( ) } ";
286+
287+ var result = await client . GetWithQueryStringsAsync ( uri , new [ ] {
288+ "timeMin" , GetProperDateTimeFormat ( timeMin ) ,
289+ "timeMax" , GetProperDateTimeFormat ( timeMax ) ,
290+ "timeZone" , timeZone
291+ } ) ;
285292
286293 string contentResult = await result . Content . ReadAsStringAsync ( ) ;
287294 var model = JsonSerializer . Deserialize < GoogleCalendarEventRoot > ( contentResult ) ;
@@ -291,7 +298,7 @@ public async Task<GoogleCalendarEventRoot> GetEvents(DateTime timeMin, DateTime
291298 return model ;
292299 }
293300
294- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
301+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
295302 return await GetEvents ( timeMin , timeMax , calendarId , maxResults ) ;
296303 }
297304
@@ -315,7 +322,7 @@ public async Task<GoogleCalendarEventModel> GetEventById(string eventId, string
315322 return json ;
316323 }
317324
318- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
325+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
319326 return await GetEventById ( eventId , calendarId ) ;
320327 }
321328
@@ -343,7 +350,7 @@ public async Task<string> AddEvent(GoogleCalendarEventModel calendarEvent, strin
343350 return contentResult ;
344351 }
345352
346- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
353+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
347354 await AddEvent ( calendarEvent , calendarId ) ;
348355 return "" ;
349356 }
@@ -385,7 +392,7 @@ public async Task<string> UpdateEvent(GoogleCalendarEventModel newCalendarEvent,
385392 return contentResult ;
386393 }
387394
388- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
395+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
389396 await UpdateEvent ( newCalendarEvent , eventId , calendarId ) ;
390397 return "" ;
391398 }
@@ -553,7 +560,7 @@ public async Task DeleteEvent(string eventId, string calendarId, bool forceAcces
553560 return ;
554561 }
555562
556- AccessToken = AuthService . RefreshAccessToken ( _refreshToken ) ;
563+ AccessToken = await AuthService . RefreshAccessToken ( _refreshToken ) ;
557564 await DeleteEvent ( eventId , calendarId ) ;
558565 }
559566
0 commit comments