Google Calendar api CalendarList List returns an empty element

EDIT: The original poster asked about 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

empty. At https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list , when I try api, I get a good result.

I really don't understand why I don't have any result: it looks like if service_account does not have the same calendar as my gmail account associated with.

Any suggestion? Thanks.

+6
source share
1 answer

The solution is to share an existing calendar with a service account

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

(You can find the corresponding account in the credentials tab in the Google Developers Console called "Email Address")

+10
source

Source: https://habr.com/ru/post/970395/


All Articles