【问题标题】:Not found exception when executing request in service account在服务帐户中执行请求时未发现异常
【发布时间】:2016-07-01 08:53:50
【问题描述】:

使用服务帐户检索日历中的事件时出现以下错误。

谁能告诉我我做错了什么。

未找到 Google.Apis.Requests.RequestError [404] 错误 [消息 [未找到] 位置 [-] 原因 [未找到] 域 [全局]] //文件路径 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();  

感谢您对我有帮助的任何回答。

【问题讨论】:

    标签: google-calendar-api service-accounts


    【解决方案1】:

    通常遇到404: Not found时找不到指定的资源。这可能在多种情况下发生。

    • 当请求的资源从未存在时。
    • 访问用户无法访问的日历时。

    根据 Google 官方文档,建议的操作是实施 exponential backoff

    Exponential backoff 是网络应用程序的标准错误处理策略,在这种策略中,客户端会在越来越长的时间内定期重试失败的请求。如果大量请求或繁重的网络流量导致服务器返回错误,指数退避可能是处理这些错误的好策略。相反,它不是处理与速率限制、网络容量或响应时间无关的错误的相关策略,例如无效的授权凭据或找不到文件错误。

    如果使用得当,指数退避可以提高带宽使用效率,减少获得成功响应所需的请求数量,并最大限度地提高并发环境中的请求吞吐量。

    请注意,在每个请求中,您的应用程序都会发送到 Google Calendar API must include an authorization 令牌。该令牌还会向 Google 识别您的应用程序。

    这是遇到的相关 SO 票证404 not found 错误:Error 404 when creating a calendar with Google Calendar Api v3 using c# .net

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      相关资源
      最近更新 更多