Avoid Google Calendar API adding an actual event in peoples calendars?

I am using the Google Calendar API with a service account. Idea is that we want to use it purely as an API backend, so we don't have to code it ourselves. That means we do not want it to interfere (or at least make it optional!) with peoples real calendar.

If I make a POST like this:

        var resultingex = service.Calendars.Insert(new Calendar()
        {
            Summary = "Nice new calendar",

        }).Execute();

        var eventIsNice = service.Events.Import(new Event()
        {
            Summary = "I'm a nice event",
            Location = "Copenhagen, Denmark",
            Start = new EventDateTime() { DateTime = DateTime.Now.AddMinutes(15) },
            End = new EventDateTime() { DateTime = DateTime.Now.AddMinutes(45) },
            Attendees = new List<EventAttendee>() { new EventAttendee() { Email = "lars@asano.dk" } },


        }, resultingex.Id).Execute();

It will add to my Google Calendar. That means I cannot use it purely as a backend, as it calls my real calendar.

So my question is: how do I add events that is only existing inside my applications context?

This is how I authenticate with the service:

            var credPath = "client_secret.json";

            var json = File.ReadAllText(credPath);
            var cr = JsonConvert.DeserializeObject<PersonalServiceAccountCred>(json); // "personal" service account credential

            // Create an explicit ServiceAccountCredential credential
            var xCred = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(cr.client_email)
            {
                Scopes = new[] {
                    CalendarService.Scope.Calendar,
                    CalendarService.Scope.CalendarReadonly,
        }
            }.FromPrivateKey(cr.private_key));

            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = xCred,
                ApplicationName = ApplicationName,
            });
Jon Skeet
people
quotationmark

It sounds like your application needs its own calendar - so create one (see Calendars.insert for how to do this programmatically).

Whether you need a single calendar for the whole application, regardless of user (in which case you'd probably want to use service account authentication, and create a single calendar associated with the service account) or an extra calendar per user (in which case you'll use user authentication and create another calendar in their account) depends on your application needs.

It's worth being aware that if you create a calendar in the user's account, they almost certainly could access it via the web UI. Again, whether that's a problem or not depends on the application.

people

See more on this question at Stackoverflow