Google Calendar API, Adding an event to someones calendar just by knowing their e-mail address

api, asp.net, c#, calendar, google-api

Solution

There are syntax errors in the part where you create the event and insert it. Here is a snippet that has correct syntax for the Google API .NET library:

Event myEvent = new Event
{
  Summary = "Appointment",
  Location = "Somewhere",
  Start = new EventDateTime() {
      DateTime = new DateTime(2014, 6, 2, 10, 0, 0),
      TimeZone = "America/Los_Angeles"
  },
  End = new EventDateTime() {
      DateTime = new DateTime(2014, 6, 2, 10, 30, 0),
      TimeZone = "America/Los_Angeles"
  },
  Recurrence = new String[] {
      "RRULE:FREQ=WEEKLY;BYDAY=MO"
  },
  Attendees = new List<EventAttendee>()
      {
        new EventAttendee() { Email = "johndoe@gmail.com" }
      }
};

Event recurringEvent = service.Events.Insert(myEvent, "primary").Execute();

Problem

I have downloaded the Google.Apis namespace: ``` using Google.Apis.Auth.OAuth2; using Google.Apis.Calendar.v3; using Google.Apis.Calendar.v3.Data; using Google.Apis.Services; ``` I've spent the entire day looking on the web to see .NET samples about how I can possible add an event to someones calendar just by knowing their e-mail address. I tried the following code, but it's bringing up errors and it's quite obvious that it isn't going to work: ``` Public void Method(string email, string text) { UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = "CLIENTID", ClientSecret = "CLIENTSECRET", }, new[] { CalendarService.Scope.Calendar }, "user", CancellationToken.None).Result; // Create the service. var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Calendar API Sample", }); Event event1 = new Event() { Summary = "Something", Location = "Somewhere", Start = new EventDateTime() { DateTime = DateTime.Now, TimeZone = "America/Los_Angeles" }, End = new EventDateTime() { DateTime = DateTime.Now, TimeZone = "America/Los_Angeles" }, Attendees = new List<EventAttendee>() { new EventAttendee() { Email: email } //bringing up an error "Syntax ',' expected } }; Event thisevent = service.Events.Insert(event1, "primary").Fetch(); // Another error. "Does not contain a definition for Fetch" } ``` Any help is appreciated! Even samples of other code :)

Original source