我编写了一些代码来向 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 应该在那里。
关于c# - 创建 Google 日历事件后获取事件 ID C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71339013/