gpt4 book ai didi

c# - 仅使用 "Free/Busy time, subject, location"权限级别通过 EWS 从同事那里获取约会

转载 作者:行者123 更新时间:2023-11-30 23:13:08 25 4
gpt4 key购买 nike

我想通过他的电子邮件从我的同事那里获得特定日期范围内的所有约会。我可以通过 outlook 访问他的日历。我只想知道他是否将约会设置为“空闲”、“忙碌”或“OOF”。该代码适用于“完整详细信息”权限,但不适用于“空闲/忙碌时间、主题、位置”权限级别。

我的同事不应将权限级别更改为“详细信息”。它应该保持在“空闲/忙碌时间、主题、位置”上,如下所示:

enter image description here

我有以下代码:

private static void GetAllCalendarItems()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.UseDefaultCredentials = true;
service.Url = new Uri("https://example.com/EWS/Exchange.asmx");

FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "coworker@mexample.com");
Folder TargetFolder = Folder.Bind(service, cfolderid);
CalendarFolder calendar = CalendarFolder.Bind(service, cfolderid);

CalendarView cView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(30), 5);

cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.LegacyFreeBusyStatus);

FindItemsResults<Appointment> appointments = null;
try
{
appointments = calendar.FindAppointments(cView);
}
catch (ServiceResponseException ex)
{
Debug.WriteLine("Error code: " + ex.ErrorCode);
Debug.WriteLine("Error message: " + ex.Message);
Debug.WriteLine("Response: " + ex.Response);
}

foreach (Appointment a in appointments)
{
Debug.Write("Subject: " + a.Subject.ToString() + "\t\t\t");
Debug.Write("Status: " + a.LegacyFreeBusyStatus.ToString() + "\t\t\t");
Debug.WriteLine("");
}

}

此代码适用于我的电子邮件。但不是我同事的那个。我在 try-catch-block 中得到以下异常:

Exception thrown: 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' in Microsoft.Exchange.WebServices.dll
Error code: ErrorAccessDenied
Error message: Access is denied. Check credentials and try again.
Response: Microsoft.Exchange.WebServices.Data.FindItemResponse`1[Microsoft.Exchange.WebServices.Data.Appointment]

我可以使用给定的权限访问他的日历,因为我可以在 outlook 中看到他的约会,那么我如何通过他的电子邮件从我的同事那里获得约会状态?

最佳答案

如果这适用于审阅者权限而不是空闲/忙碌设置,我只能假设您需要审阅者权限级别才能阅读日历。

获取空闲/忙碌时间的另一种方法是使用 ExchangeService.GetUserAvailability

请参阅以下资源:

https://msdn.microsoft.com/en-us/library/office/dn643673(v=exchg.150).aspx https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.getuseravailability(v=exchg.80).aspx

来自上面链接的代码以防将来中断:

// Create a collection of attendees. 
List<AttendeeInfo> attendees = new List<AttendeeInfo>();

attendees.Add(new AttendeeInfo()
{
SmtpAddress = "mack@contoso.com",
AttendeeType = MeetingAttendeeType.Organizer
});

attendees.Add(new AttendeeInfo()
{
SmtpAddress = "sadie@contoso.com",
AttendeeType = MeetingAttendeeType.Required
});

// Specify options to request free/busy information and suggested meeting times.
AvailabilityOptions availabilityOptions = new AvailabilityOptions();
availabilityOptions.GoodSuggestionThreshold = 49;
availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
availabilityOptions.MaximumSuggestionsPerDay = 2;
// Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
availabilityOptions.MeetingDuration = 60;
availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

// Return free/busy information and a set of suggested meeting times.
// This method results in a GetUserAvailabilityRequest call to EWS.
GetUserAvailabilityResults results = service.GetUserAvailability(attendees,
availabilityOptions.DetailedSuggestionsWindow,
AvailabilityData.FreeBusyAndSuggestions,
availabilityOptions);

关于c# - 仅使用 "Free/Busy time, subject, location"权限级别通过 EWS 从同事那里获取约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43759529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com