1

I was creating the sample to get all the google calendar events and show the events with details on list. But it always throws the exception while fetching the data.

I tried to get events by follow the below link https://www.c-sharpcorner.com/article/get-and-create-google-calendar-events-from-net/

and i also refer the google link also https://developers.google.com/api-client-library/dotnet/get_started#simple

The issue was raised on make a request and i tried with both API key and client service.

I created the calendar credential by

    GoogleCredential credential;  
  using(var stream = new FileStream(keyfilepath, FileMode.Open, FileAccess.Read)) {     
   credential = GoogleCredential.FromStream(stream)  
    .CreateScoped(Scopes).CreateWithUser("demo123@gmail.com");  
  }  
  var service = new CalendarService(new BaseClientService.Initializer() {  
   HttpClientInitializer = credential,  
    ApplicationName = "Calendar Sample",  
  }); 
EventsResource.ListRequest request = service.Events.List("primary"); 
Events events = request.Execute(); /// Makes crash

Android Crash : System.Net.WebException: 'Unable to resolve host "oauth2.googleapis.com": No address associated with hostname'

Windows : Google.Apis.Auth.OAuth2.Responses.TokenResponseException: 'Error:"unauthorized_client", Description:"Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.", Uri:""'

Suggest me to resolve the problem.

  • 1
    Can you show us your code? that would make it easier for us to understand what could be causing the issue – FreakyAli Dec 23 '21 at 14:02
  • Also paste the text of the exception into your question. Its always helpful to see exactly what the exception was. – ToolmakerSteve Dec 23 '21 at 20:13
  • Unfortunately it is not easy; Google decided [not to maintain support for Xamarin](https://github.com/googleapis/google-api-dotnet-client/blob/main/FAQ.md#why-arent-unity-xamarin-or-uwp-supported). Perhaps next year when Maui is a final release, they might decide to support it. One person did get it [working for xamarin UWP](https://stackoverflow.com/a/53971436/199364). You might be able to adapt what they did, to work on Android and iOS. – ToolmakerSteve Dec 23 '21 at 20:32
  • @FreakyAli I was updated the post with crash code and exception – StackOverflow User Dec 27 '21 at 07:32
  • @ToolmakerSteve I was updated the post with crash code and exception – StackOverflow User Dec 27 '21 at 07:33
  • My conclusion from the links I provided, is that it will be quite challenging to get this to work. You might have to wait until google updates their .NET calendar support to work with ".net 6 for android" and ".net 6 for ios". I assume they (or someone else) will do this, sometime in 2022. A month or two from now, google `google calendar api for .net 6 for android and ios`. Maybe someone will have figured it out by then. – ToolmakerSteve Dec 27 '21 at 22:27

0 Answers0