Google api Google calendar api CalendarList返回空元素
编辑:原始海报要求使用Google api Google calendar api CalendarList返回空元素,google-api,google-calendar-api,Google Api,Google Calendar Api,编辑:原始海报要求使用C,但无论使用何种库,都会出现相同的问题,其解决方案是独立于语言的 使用C#lib 字符串服务\u帐户=”myaccount@developer.gserviceaccount.com"; var certificate=new X509Certificate2(@“pathty privatekey.p12”,“notasecret”,x509keystargeflags.Exportable); ServiceAccountCredential credential=新
C
,但无论使用何种库,都会出现相同的问题,其解决方案是独立于语言的
使用C#lib
字符串服务\u帐户=”myaccount@developer.gserviceaccount.com";
var certificate=new X509Certificate2(@“pathty privatekey.p12”,“notasecret”,x509keystargeflags.Exportable);
ServiceAccountCredential credential=新ServiceAccountCredential(
新ServiceAccountCredential.初始值设定项(服务帐户)
{
Scopes=new[]{CalendarService.Scope.Calendar}
}.FromCertificate(证书));
//创建服务。
var service=new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=“我的项目名称”,
});
var calendarList=service.calendarList.List().Execute();
IList items=calendarList.items;
项目为空。在上,当我尝试api时,我得到了很好的结果
我真的不明白为什么我没有任何结果:似乎如果服务帐户没有与我的gmail帐户链接的相同日历
有什么建议吗?
谢谢。解决方案是与服务帐户共享现有日历
@developer.gserviceaccount.com
(你可以在Google开发者控制台的
凭证选项卡下找到有问题的帐户,它被称为“电子邮件地址”)@aldanux-你在说什么?这正是问题的解决办法。@Rototo-非常感谢,我一个小时以来一直在做这个,不知道下一步该做什么!你救了我一天…:)在与服务帐户共享日历后,日历列表对我来说仍然是空的。在我与服务帐户共享第二个日历后,两个日历都出现了。在无意中使用此解决方案之前,我差点把头发拔了出来,因此如果您仍然被卡住,可能会有所帮助。可能很明显,但我第一次错过了它:仅将地址粘贴到日历设置页面并按return是不够的,您还需要单击“保存”-直到它变为活动状态…此外:如果您使用的是谷歌应用程序域,它的日历共享级别可能最高,仅限于“忙/闲信息”-因此您可以查看事件,但标题等将为空。此外,它不会警告您发生了这种情况——您最终会注意到日历中的“权限设置”是错误的。您可以在应用程序>谷歌应用程序>日历设置中更改此设置;我发现我需要注销有问题的帐户,然后重新登录。
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;