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 :)
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.
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.
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!
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With