Google日历api CalendarList列表返回空元素

Rot*_*oto 7 google-calendar-api google-api

编辑:原始海报问这个C#问题,但无论使用哪个库,都会出现同样的问题,其解决方案与语言无关.

使用C#lib,

        string service_account = "myaccount@developer.gserviceaccount.com";

        var certificate = new X509Certificate2(@"pathtomy-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable);

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


        // Create the service.
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "My project name",

        });

        var calendarList = service.CalendarList.List().Execute();
        IList<CalendarListEntry> items = calendarList.Items;
Run Code Online (Sandbox Code Playgroud)

物品是空的.在https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list上,当我尝试使用api时,我得到了很好的结果.

我真的不明白为什么我没有任何结果:似乎如果service_account与我的gmail帐户链接的日历不同.

有什么建议吗?谢谢.

Rot*_*oto 14

解决方案是与服务帐户共享现有日历

<paste-your-account-here>@developer.gserviceaccount.com

(您可以credentials在Google Developers Console 的标签下找到相关帐户,它被称为'EMAIL ADDRESS')