EDIT:原来的海报要求这个C#
,但是无论使用什么库都会出现同样的问题,其解决方案是独立于语言.
使用 C# 库,
string service_account = "[email protected] /cdn-cgi/l/email-protection";
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 https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list,当我尝试API时,我得到了很好的结果。
我真的不明白为什么我没有任何结果:好像 service_account 没有与我的 Gmail 帐户链接的日历相同。
有什么建议吗?
谢谢。
解决方案是与服务帐户共享现有日历
<paste-your-account-here>@developer.gserviceaccount.com
(您可以在以下位置找到相关帐户credentials
Google Developers Console 中的选项卡,称为“电子邮件地址”)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)