我写了一些代码来向Google Calander:添加事件
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "ID",
ClientSecret = "Secret",
},
new[] { CalendarService.Scope.Calendar },
Account.Text,
CancellationToken.None).Result;
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "Custom CRM",
});
var myEvent = new Event
{
Summary = Title.Text,
Location = AppointmentLocation.Text,
ColorId = Convert.ToString(AppointmentColourInt),
Description = Description.Text,
Start = new EventDateTime()
{
DateTime = new DateTime(StartDate.Value.Year, StartDate.Value.Month, StartDate.Value.Day, Convert.ToInt32(StartTime.Text.Substring(0, 2)), Convert.ToInt32(StartTime.Text.Substring(StartTime.Text.Length - 2)), 00),
TimeZone = "Europe/London"
},
End = new EventDateTime()
{
DateTime = new DateTime(EndDate.Value.Year, EndDate.Value.Month, EndDate.Value.Day, Convert.ToInt32(EndTime.Text.Substring(0, 2)), Convert.ToInt32(EndTime.Text.Substring(EndTime.Text.Length - 2)), 00),
TimeZone = "Europe/London"
},
};
var recurringEvent = service.Events.Insert(myEvent, CalendarID);
recurringEvent.SendNotifications = true;
recurringEvent.Execute();
有没有一种方法可以在创建事件后获取事件的ID,以便将其保存到数据库中以供将来参考?
谢谢。
var recurringEvent = service.Events.Insert(myEvent, CalendarID);
recurringEvent.SendNotifications = true;
var results = recurringEvent.Execute();
执行将返回给您它插入的对象。Id应该在里面。