I am using "Google.GData.Calendar" API to add Events to the Google Calendar using c#. But there is time difference between the events created in my DB and Google Calendar.
Following is the Code to add an Event to Google Calendar using the Google.GData API:
public static void AddEventToGoogle()
{
//string timezone = "US Mountain Standard Time";
Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");
try
{
GOAuthRequestFactory authFactory = new GOAuthRequestFactory("cl", "MyApp");
authFactory.ConsumerKey = ConfigurationManager.AppSettings["GConsumerKey"].ToString();
authFactory.ConsumerSecret = ConfigurationManager.AppSettings["GConsumerKeySecret"].ToString();
authFactory.Token = "xxxxxxxxxx";
authFactory.TokenSecret = "xxxxxx";
Google.GData.Calendar.CalendarService service = new Google.GData.Calendar.CalendarService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
EventEntry entry = new EventEntry();
entry.Title.Text = "Test Google Event Create";
entry.Content.Content = "Test Google Event Create";
entry.Notifications = false;
When eventTime = new When();
eventTime.AllDay = false;
eventTime.StartTime = new DateTime(2013, 5, 9, 8, 0, 0);
eventTime.EndTime = new DateTime(2013, 5, 9, 11, 0, 0);
entry.Times.Add(eventTime);
// Send the request and receive the response:
EventEntry insertedEntry = service.Insert(postUri, entry);
if (insertedEntry != null && !string.IsNullOrEmpty(insertedEntry.EventId))
{
//Get the insertedEntry.EventId
}
}
catch (GDataRequestException gre)
{
HttpWebResponse response = (HttpWebResponse)gre.Response;
}
}
But with the above code there is a time difference with the event I intended to create and the entry in the Google Calendar. The TimeZone I have in my Google Calendar is "(GMT-07:00) Mountain Time - Arizona". This is happening when i change the TimeZones of my Google Calendar to CST, PST,...
Please suggest a workaround for this situation or where do I need to specify the TimeZone while adding an event to Google Calendar.
Updated my question with the complete method i used to add an event
The GData library uses v2 of the Google APIs. I think you will need to migrate your code to v3 in order to get proper support for time zones on events.
For example, see this page which shows an example of creating a recurring event. (Switch to the ".NET" tab".
Here are some resources that may help you:
Migration Guide
What's new in v3 (it doesn't mention time zones though)
Client libraries (see the ".NET" tab)
I did look through your code and the reference guide to the v2 GData library. I only see TimeZone properties on the CalendarEntry, EventFeed, and EventQuery classes. Since you're not using any of those, I don't think it is possible in v2.
UPDATE
It is possible in the v2 API. You can pass a time zone in the ICAL formatted <gd:recurrence> tag. Take a look at the note following the example in this documentation.
However, it doesn't appear that it is exposed as a property of the EventEntry class in the .Net GData client library. So my recommendation stands - use the v3 api and client library.
Related
I am currently working out the Microsoft Graph tutorial with C# .Net Core, and in the process I came across the following C#-method for Subscription:
[HttpGet]
public async Task<ActionResult<string>> Get()
{
var graphServiceClient = GetGraphClient();
var sub = new Microsoft.Graph.Subscription();
sub.ChangeType = "updated";
sub.NotificationUrl = config.Ngrok + "/api/notifications";
sub.Resource = "/users";
sub.ExpirationDateTime = DateTime.UtcNow.AddMinutes(15);
sub.ClientState = "SecretClientState";
var newSubscription = await graphServiceClient
.Subscriptions
.Request()
.AddAsync(sub);
Subscriptions[newSubscription.Id] = newSubscription;
if (subscriptionTimer == null)
{
subscriptionTimer = new Timer(CheckSubscriptions, null, 5000, 15000);
}
return $"Subscribed. Id: {newSubscription.Id}, Expiration: {newSubscription.ExpirationDateTime}";
}
and wanted to know how I can change it for sharepoint lists instead of users.
If I change it to /sites/{site-id} or similar it does not work. (see sub.Resource)
Github-Link: MS Repo
Microsoft Graph API uses a webhook mechanism to deliver change notifications to clients. Using the Microsoft Graph API, an app can subscribe to changes for list under a SharePoint site.
Resource Path - Changes to content within the list:
/sites/{id}/lists/{id}
For details round how to subscribe to and handle incoming notifications, see Set up notifications for changes in user data
Also make sure you check necessary permissions needed here.
I found the solution myself with the sub.Resource: /sites/{site-id}/lists/{list-id}
I have been using Exchange WebServices (EWS) for some time now, in Asp.net C #, to add events in the calendars of Office365 users at my work.
I now needed those same events to appear at Microsoft Teams, with the possibility of going on videoconference.
Events appear but that possibility is not present.
One of the properties of "appointments" is "isOnlineMeeting". I tried to add it, making it true, but it always returns an error saying "Set action is invalid for property.".
In the online searches I have done, I have found that this is a read-only property.
So, is there any chance that I can "force" this property?
I have already configured my Exchange so that, in Outlook online when we do a new event, this is always by videoconference.
Some help?
Thank you!
UPDATE:
By the way, the code that I'm using is:
try {
ExchangeService service = new ExchangeService (ExchangeVersion.Exchange2013_SP1, TimeZoneInfo.FindSystemTimeZoneById ("GMT Standard Time"));
service.Url = new Uri ("https://outlook.office365.com/EWS/Exchange.asmx");
string User = "a#a.net";
string Password = "AAA";
service.Credentials = new NetworkCredential (User, Password);
Appointment appointment = new Appointment (service);
appointment.Subject = "Experiment";
appointment.Location = "Videoconference";
string dataStart = "10-02-2021 19:00:00.000";
string dataEnd = "10-02-2021 20:00:00.000";
appointment.Start = DateTime.Parse (dataStart);
appointment.End = DateTime.Parse (dataEnd);
appointment.Body = "<strong>Ignore! Just a test</strong>";
appointment.IsOnlineMeeting = true;
appointment.RequiredAttendees.Add ("b#a.net");
appointment.Save (SendInvitationsMode.SendOnlyToAll);
} catch (Exception ex) {
}
Posting the Answer for better knowledge
Copying from comments
Could you please try with this document by using Graph API. By using Graph API we can set "isOnlineMeeting" property to true, and "onlineMeetingProvider" property to "teamsForBusiness".
Events inserted using google's api and service account shows up fine when I view the calendar, but they are not included when I print the calendar.
Events manually inserted are printed as expected. I am using the following code.
string[] scopes = new string[] { CalendarService.Scope.Calendar };
GoogleCredential credential;
using (var stream = new FileStream("mikeServiceAccount.json", FileMode.Open,
FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(scopes);
}
// Create the Calendar service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Calendar Authentication Sample",
});
Event myEvent = new Event
{
Summary = "Summary Title",
Description = "event description"
Location = "Nashville, TN"
Start = new EventDateTime()
{
Date = "2018-10-19"
},
End = new EventDateTime()
{
Date = "2018-10-19"
}
};
service.Events.Insert(myEvent,"b4sbsrsdf9r82sbj0#group.calendar.google.com").Execute();
Here is a composite screen shot of what I see when I view and print the calendar. https://i.stack.imgur.com/8FqAk.png
I was able to work this out, but it was really just ended up being a proof of concept, so I don't have code I look back on. As I remember it the problem ended up being the value I used as my endDate. I don't remember specifics, but maybe I used the same date as the startDate and added the end time of midnight. Something like that anyway. Good luck and sorry I couldn't be more helpful.
Using the information provided by mikeh as a hint,
we were able to resolve the issue "All-day events are not displayed when printing".
The solution in my case by...
setting the start to "YYYY-MM-DDT00:00:00" and...
setting the end to 00:00:00 on the "next day" of the start.
Thank you.
start: {
dateTime : new Date("2020-01-25T00:00:00").toISOString()
,timeZone: 'Asia/Tokyo'
}
,end: {
dateTime : new Date("2020-01-26T00:00:00").toISOString()
,timeZone: 'Asia/Tokyo'
}
I'm testing out the Google Calendar API v3 on .Net. I've managed to add an event to a calendar as follows:
Google.Apis.Calendar.v3.Data.EventAttendee attendee = new Google.Apis.Calendar.v3.Data.EventAttendee();
attendee.Email = "[email]#gmail.com";
List<Google.Apis.Calendar.v3.Data.EventAttendee> event_attendees = new List<Google.Apis.Calendar.v3.Data.EventAttendee>();
event_attendees.Add(attendee);
Google.Apis.Calendar.v3.Data.Event new_event = new Google.Apis.Calendar.v3.Data.Event();
new_event.Summary = "GoogleCalendarTest: Testing Event 4";
new_event.Description = "Testing .Net Google Calendar API";
new_event.Location = "Offices";
new_event.Start = new Google.Apis.Calendar.v3.Data.EventDateTime();
new_event.Start.DateTime = DateTime.Now;
new_event.End = new Google.Apis.Calendar.v3.Data.EventDateTime();
new_event.End.DateTime = new DateTime(2014, 12, 15, 12, 0, 0);
new_event.Attendees = event_attendees;
service.Events.Insert(new_event, "[email]#gmail.com").Execute();
I thought this would automatically send an invite email to the attendee but it seems that by default it is not sent as seen here in the documentation. The sendNotifications parameter is added is an optional parameter, this question shows how it's done on PHP but I can't figure how to add this on .Net.
UPDATE
Figured out a way to set sendNotifications on .Net:
Google.Apis.Calendar.v3.EventsResource.InsertRequest insert_event = new EventsResource.InsertRequest(service, new_event, "[email]#gmail.com");
insert_event.SendNotifications = true;
insert_event.Execute();
Still not sending an invitation email though, might still be doing something wrong.
UPDATE 2
Version issue?
I've found this question: Google Calendar API for .Net: Email notifications not sent when creating calendar event, which is very similar to the problem I have. Uninstalling and installing the API solved the problem...I tried this out but still have the same problem, currrent version: 1.9.0
This worked for me:
EventsResource.InsertRequest request = service.Events.Insert(newEvent, "primary");
request.SendNotifications = true;
Event createdEvent = request.Execute();
I want to send events to my google calendar account from asp.net application
Have a look at Google API Calendar
http://code.google.com/intl/nl-NL/apis/calendar/
http://code.google.com/intl/nl-NL/apis/calendar/data/2.0/developers_guide_dotnet.html#CreatingSingle
Create single-occurance event
EventEntry entry = new EventEntry();
// Set the title and content of the entry.
entry.Title.Text = "Tennis with Beth";
entry.Content.Content = "Meet for a quick lesson.";
// Set a location for the event.
Where eventLocation = new Where();
eventLocation.ValueString = "South Tennis Courts";
entry.Locations.Add(eventLocation);
When eventTime = new When(DateTime.Now, DateTime.Now.AddHours(2));
entry.Times.Add(eventTime);
Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full");
// Send the request and receive the response:
AtomEntry insertedEntry = service.Insert(postUri, entry);
look at the API
Like Murph said in the comment, link to the guide for .Net API