Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :)

like image 989
NetUser101 Avatar asked Apr 26 '14 11:04

NetUser101


People also ask

Can I add events to someone else's Google Calendar?

Important: You can only add a calendar with a link if the other person's calendar is public. Learn more about public calendars. On your computer, open Google Calendar.

How do I add an event to someone else's calendar in Gmail?

Adding an event to a shared Google Calendar: To do so, click on the calendar that is currently selected, to see a drop down of all your calendar options. Then, click on the shared calendar you want to add your event to.

Can you link an email to a Google Calendar event?

When you have your calendar event ready for an attachment, select Add attachment. Select the email you just saved as a PDF in your Google Drive. Complete the details of your event and send your invite!

How do I add a list of email addresses to my Google Calendar invite?

A neat tip when setting up a new event or meeting in Google Calendar. To add all members of an email group, type the group email address in to the Add box. All members will be added to the attendees list. You can then edit them as normal.


1 Answers

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 = "[email protected]" }
      }
};

Event recurringEvent = service.Events.Insert(myEvent, "primary").Execute();
like image 80
Mark Avatar answered Oct 02 '22 16:10

Mark