gpt4 book ai didi

google-api - 谷歌日历api CalendarList列表返回空元素

转载 作者:行者123 更新时间:2023-12-04 10:18:09 25 4
gpt4 key购买 nike

编辑:原发帖人问这个要C# ,但是不管使用什么库都会出现同样的问题,其解决方法是语言无关 .

使用 C# 库,

        string service_account = "myaccount@developer.gserviceaccount.com";

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 帐户链接的日历不同。

有什么建议吗?
谢谢。

最佳答案

解决方案是与服务帐户共享现有日历
<paste-your-account-here>@developer.gserviceaccount.com
(您可以在 Google Developers Console 的 credentials 标签下找到相关帐户,它称为“电子邮件地址”)

关于google-api - 谷歌日历api CalendarList列表返回空元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24062762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com