如何使用EWS API Outlook从其他用户处获取日历项

如何使用EWS API Outlook从其他用户处获取日历项,outlook,exchange-server,exchangewebservices,Outlook,Exchange Server,Exchangewebservices,我想了解一下其他人的日历。当我使用方法1时,我可以获得他的日历信息,但“事件”项目不在 使用方法2,我可以获取此人的事件项,但它显示的是我的日历项,而不是此人,而我传递的是此人的电子邮件地址 在这两种情况下,我都在传递包含其他人电子邮件地址的“service”参数 我需要X个人的所有日历信息+事件。。。为什么方法2给出的是我的日历项而不是那个人 有什么建议吗 方法1:方法->文件夹。使用绑定 string username ="SomeOneElseEmail@outlook.com" Exch

我想了解一下其他人的日历。当我使用方法1时,我可以获得他的日历信息,但“事件”项目不在

使用方法2,我可以获取此人的事件项,但它显示的是我的日历项,而不是此人,而我传递的是此人的电子邮件地址

在这两种情况下,我都在传递包含其他人电子邮件地址的“service”参数

我需要X个人的所有日历信息+事件。。。为什么方法2给出的是我的日历项而不是那个人

有什么建议吗

方法1:方法->文件夹。使用绑定

string username ="SomeOneElseEmail@outlook.com"
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.UseDefaultCredentials = true;
folderIdFromCalendar = new FolderId(WellKnownFolderName.Calendar, username);
PropertySet propertySet = new PropertySet(AppointmentSchema.Subject);
Folder TargetFolder = Folder.Bind(service, folderIdFromCalendar, propertySet);
方法2:使用方法->FindApoints

  service.AutodiscoverUrl(username, RedirectionUrlValidationCallback);
                /////////

                DateTime startDate = DateTime.Now;
                DateTime endDate = startDate.AddDays(30);
                const int NUM_APPTS = 5;

                // Initialize the calendar folder object with only the folder ID. 
                CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());

                // Set the start and end time and number of appointments to retrieve.
                CalendarView ccView = new CalendarView(startDate, endDate, NUM_APPTS);

                // Limit the properties returned to the appointment's subject, start time, and end time.
                ccView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

                // Retrieve a collection of appointments by using the calendar view.
                FindItemsResults<Appointment> appointments2 = calendar.FindAppointments(ccView);

                Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() +
                                  " to " + endDate.Date.ToShortDateString() + " are: \n");

                foreach (Appointment a in appointments2)
                {
                    Console.Write("Subject: " + a.Subject.ToString() + " ");
                    Console.Write("Start: " + a.Start.ToString() + " ");
                    Console.Write("End: " + a.End.ToString());
                    Console.WriteLine();
                }
service.AutodiscoverUrl(用户名,重定向URL验证回调);
/////////
DateTime startDate=DateTime.Now;
DateTime endDate=开始日期。添加日期(30);
常量int NUM_APPTS=5;
//仅使用文件夹ID初始化日历文件夹对象。
CalendarFolder calendar=CalendarFolder.Bind(服务,WellKnownFolderName.calendar,新属性集());
//设置要检索的开始和结束时间以及约会数。
CalendarView ccView=新的CalendarView(开始日期、结束日期、数值应用);
//限制返回到约会主题、开始时间和结束时间的属性。
ccView.PropertySet=newpropertyset(appointschema.Subject,appointschema.Start,appointschema.End);
//使用日历视图检索约会集合。
FindItemsResults appointments2=calendar.FindAppoints(ccView);
Console.WriteLine(“\n日历上的第一个”+NUM_APPTS+”约会从“+startDate.Date.ToShortDateString()开始)+
“到”+endDate.Date.ToShortDateString()+“是:\n”);
foreach(任命中的a任命2)
{
Console.Write(“Subject:+a.Subject.ToString()+”);
编写(“Start:+a.Start.ToString()+”);
Console.Write(“End:+a.End.ToString());
Console.WriteLine();
}

方法2应该可以工作,但您需要使用FolderId的重载来指定要访问的邮箱,以便进行更改

CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());

folderIdFromCalendar = new FolderId(WellKnownFolderName.Calendar, username);
CalendarFolder calendar = CalendarFolder.Bind(service, folderIdFromCalendar , new PropertySet());