Google日历api CalendarList列表返回空元素 [英] Google calendar api CalendarList List return empty element

查看:176
本文介绍了Google日历api CalendarList列表返回空元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:原始海报询问 C#,但无论使用哪个库,都会发生同样的问题,并且其解决方案

使用C#lib,

  string service_account =myaccount@developer.gserviceaccount.com; 

var certificate = new X509Certificate2(@pathtomy-privatekey.p12,notasecret,X509KeyStorageFlags.Exportable);

ServiceAccountCredential凭证=新的ServiceAccountCredential(
新的ServiceAccountCredential.Initializer(service_account)
{
Scopes = new [] {CalendarService.Scope.Calendar}
} .FromCertificate(证书));


//创建服务。
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer =凭证,
ApplicationName =我的项目名称,

} );

var calendarList = service.CalendarList.List()。Execute();
IList< CalendarListEntry> items = calendarList.Items;

项目为空。在 https://developers.google.com/google-apps/上日历/ v3 / reference / calendarList / list ,当我尝试api时,我得到了很好的结果。



我真的不明白为什么我不喜欢没有任何结果:看起来好像service_account没有与我的gmail帐户链接的日历相同。



任何建议?
Thanks。

解决方案

解决方案是使用服务帐户共享现有日历。 b

< paste-your-account-here> @ developer.gserviceaccount.com



< (您可以在Google Developers Console的凭证标签下找到相关帐户,它被称为'EMAIL ADDRESS')


EDIT: The original poster asked this for C#, but the same problem occurs regardless of the library used, and its solution is language independent.

Using C# lib,

        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;

items is empty. On https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list, when I try the api, I get the good result.

I really don't understand why I don't have any result : seems like if the service_account do not have the same calendar as my gmail account linked to.

Any suggestion ? Thanks.

解决方案

The solution is to share the existing calendar with the service account

<paste-your-account-here>@developer.gserviceaccount.com

(You can find the account in question under the credentials tab in Google Developers Console, it's called 'EMAIL ADDRESS')

这篇关于Google日历api CalendarList列表返回空元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆