6
編輯:樓主問這個爲C#
,但無論使用的庫出現同樣的問題,它的解決方案是語言無關。谷歌日曆API CalendarList列表返回空元素
使用C#的lib,
string service_account = "[email protected]";
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;
項目是空的。在https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list上,當我嘗試api時,我得到了很好的結果。
我真的不明白爲什麼我沒有任何結果:似乎如果service_account沒有與我的gmail帳戶鏈接到相同的日曆。
有什麼建議嗎? 謝謝。
@aldanux - 你在說什麼?這完全是**問題的解決方案。 – mac
@Rototo - 非常感謝,一小時之後我就陷入了困境,不知道下一步該怎麼辦!您保存了我的一天...... :) – mac
與服務帳戶共享日曆後,日曆列表對我來說仍然顯示爲空。在與服務帳戶共享第二個日曆之後,兩者都出現了。在碰到這個解決方案之前,我差點把頭髮拉出來,所以如果你仍然陷入困境,也許會有所幫助。 – alex83