gpt4 book ai didi

google-calendar-api - 在服务帐户中执行请求时未发现异常

转载 作者:行者123 更新时间:2023-12-05 07:48:49 24 4
gpt4 key购买 nike

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

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

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

感谢您提供任何对我有帮助的答案。

最佳答案

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

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

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

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

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

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

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

关于google-calendar-api - 在服务帐户中执行请求时未发现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38141107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com