I am trying to insert an event on my Google calendar. Everything is working fine but only problem is that when I change the value of my datetimepicker, it doesn't change at the time of execution. for example, if I change the value of datetimepicker to "2014-07-25", it still will show on MessageBox as current date.
Here is my code :
private void btnsubmitevent_Click(object sender, EventArgs e)
{
try
{
new frm_addeventcal().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var exi in ex.InnerExceptions)
{
MessageBox.Show("ERROR: " + exi.Message);
}
MessageBox.Show(ex.InnerException.Message);
}
}
private async Task Run()
{
UserCredential credential;
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "my cliend id",
ClientSecret = "my secret key"
},
new[] { CalendarService.Scope.Calendar},
"my gmail id",
CancellationToken.None
);
var service = new CalendarService(new BaseClientService.Initializer() {
HttpClientInitializer = credential,
ApplicationName = "project name",
});
Event newevent = new Event();
EventDateTime start = new EventDateTime();
EventDateTime end = new EventDateTime();
start.DateTimeRaw = dateTimePicker1.Value.ToString("yyyy-MM-dd") + "T" + dateTimePicker3.Value.ToString("HH:mm:ss");
MessageBox.Show(start.DateTimeRaw); // here it shows current date although I changed the value of it.
end.DateTimeRaw = dateTimePicker2.Value.ToString("yyyy-MM-dd") + "T" + dateTimePicker4.Value.ToString("HH:mm:ss");
MessageBox.Show(end.DateTimeRaw); // same thing happens here too.
newevent.Summary = "Hello World";
newevent.Location = "my location";
newevent.Description = "Random Description";
newevent.Start = start;
newevent.End = end;
var calendarstry = service.Events.Insert(newevent, "calendar id").ExecuteAsync();
}
G
I am new to google api and async task. but I think this problem is because I am using async task.