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