【发布时间】:2015-11-02 09:02:43
【问题描述】:
我正在尝试将事件添加到我的日历中。
我在 Google Developers Console 中创建了服务帐户凭据,我可以自行授权。
我的帐户上有两个日历,但我无法使用 c# 代码将它们列出到 google API。
我的日历需要一些特殊权限吗? 在设置 (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 );
【问题讨论】:
标签: c# google-api google-calendar-api google-api-dotnet-client service-accounts