0
votes

My application works based on Servivce Account authentication very well. Can read, delete, insert entries into Google Calendar. All entries are visible on calendar website and can manage them from application and manually on website as well.

But if I manually insert new event into calendar on website that event for application is invisible. Can't manage them programmatically at all. Calendar is shared of course with google service account - added service account email address in Calendar ->Settings->Shared: Edit settings.

The same application using OAuth 2.0 works well both with manually and programmatically added entries.

My problem is to manage all entries from all users using app based on service account. Can anyone has simmilar problem and solution for that?

string[] scopes = new string[] { CalendarService.Scope.Calendar };

        var certificate = new X509Certificate2(@"My Project-xxxxxxxxx.p12", "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credentials = new ServiceAccountCredential(
             new ServiceAccountCredential.Initializer("[email protected]")
             {
                 Scopes = scopes                                          
             }.FromCertificate(certificate));

        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentials,
            ApplicationName = ApplicationName,
        });
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        // Define parameters of request.
        EventsResource.ListRequest request = service.Events.List("primary");
        request.TimeMin = DateTime.Now;
        request.ShowDeleted = false;
        request.SingleEvents = true;
        request.MaxResults = 10;
        request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

        // List events.
        Events events = request.Execute();
        Console.WriteLine("Upcoming events:");
        if (events.Items != null && events.Items.Count > 0)
        {
            foreach (var eventItem in events.Items)
            {
                string when = eventItem.Start.DateTime.ToString();
                if (String.IsNullOrEmpty(when))
                {
                    when = eventItem.Start.Date;
                }
                //Console.WriteLine("{0} {1} {2} {3} ({4})", eventItem.Status, eventItem.Summary, eventItem.Location, eventItem.Description, when);
                Console.WriteLine(" Id: {0} Start: {1} End: {2} Status: {3} Summary: {4} Location: {5} description: {6} HtmlLink: {7}",
                    eventItem.Id + '\n',
                    eventItem.Start.DateTime.ToString() + '\n',
                    eventItem.End.DateTime.ToString() + '\n',
                    eventItem.Status + '\n',
                    eventItem.Summary + '\n',
                    eventItem.Location + '\n',
                    eventItem.Description + '\n',
                    eventItem.HtmlLink);
            }
        }
        else
        {
            Console.WriteLine("No upcoming events found.");
        }

This way I check of calendar list:

 var calendars = service.CalendarList.List().Execute().Items;
            foreach (CalendarListEntry entry in calendars)
                Console.WriteLine(entry.Summary + " - " + entry.Id);

There is only one.

For example are there are 5 events on Calendar website, the same day, application lists only 3 if created from app, the 2 created manually directly on web are not listed.

1
If you have granted the service account access to the calendar It should have access to all of the events in that calendar no matter who created them. I would make sure you are looking at the correct calendar. Please edit your question and include your code and an example of the data that you are missing.DaImTo

1 Answers

0
votes

I found solution. Instead of using "primary" as primary calendar id I used calendar identifier listed by service. This solved my problem.