Google日历API -从服务器端获取事件停止工作-消息[Not Found]位置[-]原因[notFound]域[g

本文关键字:Found Not 位置 notFound 原因 消息 API 日历 服务器端 获取 停止工作 | 更新日期: 2023-09-27 18:08:22

我从另一个用户管理的日历中检索所有事件,并使用服务器端库 google . api . calendar在我们的网站上显示它们。*。它继续工作良好,因为一段时间近2个月,突然停止工作,显示这个错误。问题是,服务帐户确实拥有日历中的所有权限(查看所有详细信息),但在执行请求(request. execute ();)时莫名其妙地停止工作。有人知道这个问题的线索吗?我真的很感激。

public class GCalendarService : Service
{
    public GCalendarService(X509Certificate2 certificate, String accountName, String appName) : base(certificate, accountName, appName)
    {
        this.Scopes = new string[] {
            CalendarService.Scope.Calendar, // Manage your calendars
            CalendarService.Scope.CalendarReadonly // View your Calendars
        };
        this.InitializeCredential(certificate);
        this.GService = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = this.Credential,
            ApplicationName = appName
        });
    }
    /// <summary>
    /// Gets all the events based on a period of time
    /// </summary>
    /// <param name="calendarId">The ID of the calendar to get the events</param>
    /// <param name="minDate">The minimun date to request</param>
    /// <param name="maxDate">The max date to request</param>
    /// <param name="maxEvents">The max amount of events to retrieve</param>
    /// <returns></returns>
    public Object GetEvents(string calendarId, DateTime? minDate, DateTime? maxDate, int maxEvents) 
    {
        EventsResource.ListRequest request = ((CalendarService)this.GService).Events.List(calendarId);
        request.TimeMin = DateTime.Now;
        request.ShowDeleted = false;
        request.SingleEvents = true;
        request.MaxResults = maxEvents;
        request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
        return request.Execute();
    }

Google日历API -从服务器端获取事件停止工作-消息[Not Found]位置[-]原因[notFound]域[g

您得到的404: Not Found表示没有找到指定的资源。另一个可能的原因是,当请求的资源(具有提供的ID)从未存在或访问用户无法访问的日历时。

{
"error": {
    "errors": [
        {
            "domain": "global",
            "reason": "notFound",
            "message": "Not Found"
        }
       ],
    "code": 404,
    "message": "Not Found"
    }
}

此处建议的操作是使用指数回退。

关于服务帐户,这个SO问题可能会对您有所帮助。据此,当使用服务帐户访问专用日历时,如果您拥有包含这些日历的域,则需要执行权限委托,或者需要与服务帐户的电子邮件地址共享专用日历。