我正在嘗試將事件添加到我的日曆中。Google API v3 - 無法獲取日曆列表
我在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);
非常感謝。它幫助!我不認爲我必須爲服務帳戶添加權限。我認爲創建API憑據的帳戶權限就足夠了。再次感謝! – GigaKatowice
服務帳戶是虛擬用戶,它無權訪問任何您無權訪問的內容。但它確實有自己的谷歌驅動器,谷歌日曆...可能還有其他一些帳戶,但他們沒有任何數據就開始。 – DaImTo