Google API v3-无法获取日历列表 [英] Google API v3 - can't get list of calendars

查看:77
本文介绍了Google API v3-无法获取日历列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将活动添加到我的日历。

我在Google开发人员控制台中创建了服务帐户凭据,我可以对自己进行授权。

我的帐户上有两个日历,但我无法使用Google API的C#代码列出它们。

我的日历是否需要某些特殊权限? 在设置(calendar.google.com)选项卡上,我拥有完全权限。 获取日历列表的代码可能有问题?

 string[] scopesCal = new string[] { CalendarService.Scope.Calendar, // Manage your calendars
                                              CalendarService.Scope.CalendarReadonly, // View your Calendars
                                             };

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

         ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer( ServiceAccountEmail ) {
               Scopes = scopesCal
            }.FromCertificate( certificate ) );

         // Create the service.
         CalSrv = new CalendarService( new BaseClientService.Initializer() {
            HttpClientInitializer = credential,
            ApplicationName = "XCalendar",
         } );

         var calendars = CalSrv.CalendarList.List().Execute().Items;
         foreach ( CalendarListEntry entry in calendars )
            Console.WriteLine( entry.Summary + " - " + entry.Id );

推荐答案

您使用的是服务帐户,默认情况下服务帐户没有任何谷歌日历。您需要添加一个或授予它对您的某个成员的访问权限。

获取服务帐户电子邮件地址,并将其添加为您希望其能够访问的您帐户上的日历上的用户。

转到Google日历网站。找到日历设置,然后转到日历选项卡,找到您要访问的日历,然后单击"共享:编辑设置"添加服务帐户电子邮件地址,就像添加个人电子邮件地址一样。这将为服务帐户提供与您与任何其他用户共享服务帐户相同的访问权限。

您可能需要授予它权限"make changes to events"

提示

您只需要向其授予完全访问权限的CalendarService.Scope.Calendar即可。您可以删除CalendarService.Scope.CalendarReadonly确实没有理由同时拥有两者。

这篇关于Google API v3-无法获取日历列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆