【问题标题】:Google Calendar API - Getting events from server side stop working - Message[Not Found] Location[ - ] Reason[notFound] Domain[global]Google Calendar API - 从服务器端获取事件停止工作 - 消息 [未找到] 位置 [ - ] 原因 [未找到] 域 [全球]
【发布时间】:2016-09-21 20:37:40
【问题描述】:

我正在从另一个用户管理的 CalendarId 中检索所有事件,并使用 .Net 中的服务器端库 Google.Apis.Calendar.* 在我们的网站上显示它们。自近 2 个月以来,它一直运行良好,但突然停止工作,显示此 error。 问题是服务帐户确实拥有日历中的所有权限(查看所有详细信息),但在执行请求时无故停止工作(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();
    }

【问题讨论】:

    标签: c# google-api google-calendar-api google-api-dotnet-client service-accounts


    【解决方案1】:

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

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

    此处建议的操作使用exponential backoff

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

    【讨论】:

    • 嗨@adjuremods,非常感谢您的快速回复。问题是该服务确实具有我们需要的日历中所需的权限,正如您在这张图片中看到的 [screencast.com/t/Qzu6P5rAp2ql].你现在是否需要额外的配置?因为太疯狂了,它曾经工作了一段时间就停止工作而不更改任何代码
    • 经过几次测试,我发现它必须是域管理器方面的配置,因为只有当日历来自域中的某个人时才会发生,如果我尝试使用不同的 gmail 帐户域并与它完美运行的相同服务帐户共享它。
    猜你喜欢
    • 2022-08-03
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多