3

I get the following error when retrieving the events of my calendar using service account.

Can anyone tell me what I'm doing wrong.

Google.Apis.Requests.RequestError Not Found [404]Errors [Message[Not Found] Location[ - ] Reason[notFound] Domain[global]] //file path string GoogleOAuth2CertificatePath = Server.MapPath("GoogleStore\My Project-a725fb0190fc.p12");

 // @developer... e-mail address.
        string GoogleOAuth2EmailAddress = "939544675132-compute@developer.gserviceaccount.com";

 // certificate password ("notasecret").
        string GoogleOAuth2PrivateKey = "notasecret";


    X509Certificate2 certificate = new X509Certificate2(GoogleOAuth2CertificatePath, GoogleOAuth2PrivateKey, X509KeyStorageFlags.Exportable);

    ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(GoogleOAuth2EmailAddress)
            {                   
                Scopes = new[] { CalendarService.Scope.Calendar }                   
            }.FromCertificate(certificate));

        // Create the service.
        service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName
        });

    ListRequest request = service.Events.List(calID);          
                request.ShowDeleted = false;
                request.SingleEvents = true;              
                events = request.Execute();  

Thank you for any answer what can help me.

1 Answers1

0

Usually when encountering 404: Not found the specified resource was not found. This can happen in several cases.

  • when the requested resource has never existed.
  • when accessing a calendar that the user can not access.

Based on the Official Google Documentation, the suggested action is to implement exponential backoff.

Exponential backoff is a standard error handling strategy for network applications in which the client periodically retries a failed request over an increasing amount of time. If a high volume of requests or heavy network traffic causes the server to return errors, exponential backoff may be a good strategy for handling those errors. Conversely, it is not a relevant strategy for dealing with errors unrelated to rate-limiting, network volume or response times, such as invalid authorization credentials or file not found errors.

Used properly, exponential backoff increases the efficiency of bandwidth usage, reduces the number of requests required to get a successful response, and maximizes the throughput of requests in concurrent environments.

Take note that in every request, your application sends to the Google Calendar API must include an authorization token. The token also identifies your application to Google.

Here's a related SO ticket encountered 404 not found error: Error 404 when creating a calendar with Google Calendar Api v3 using c# .net

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30