C#代码从O365获取用户的日历信息-Error远程服务器返回错误:(401)未经授权。 [英] C# code to get calendar info of user from O365 -Error The remote server returned an error: (401) Unauthorized.
问题描述
Hi Guys,
我使用下面的代码来检索5个用户的日历事件;但最终会出现以下错误
I am using below code to retrieve calendar events of 5 users; but end up with error as below
// Exchange连接
ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2010);
//替换为正确的用户名和密码
service.Credentials = new WebCredentials("","");
service.Url = new Uri(" https://outlook.office365.com/ews/exchange.asmx"); // Office 365 Exchange API URL(如果您使用的是本地Exchange安装,则将其替换为本地服务器URL)
//本周
DateTime startDate = DayPilot.Utils.Week.FirstDayOfWeek ();
DateTime endDate = startDate.AddDays(7);
// ExchangeService Service = null;
//加载默认日历
CalendarFolder calendar = CalendarFolder.Bind(service,WellKnownFolderName.Calendar,new PropertySet());
//加载事件
CalendarView cView = new CalendarView(startDate,endDate,50);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject,AppointmentSchema.Start,AppointmentSchema.End,AppointmentSchema.Id);
FindItemsResults<约会> appointment = calendar.FindAppointments(cView);
// Exchange connection ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); // replace with proper username and password service.Credentials = new WebCredentials("", ""); service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx"); // Office 365 Exchange API URL (replace it with a local server URL if you are using a local Exchange installation) // this week DateTime startDate = DayPilot.Utils.Week.FirstDayOfWeek(); DateTime endDate = startDate.AddDays(7); //ExchangeService Service = null; // load the default calendar CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); // load events CalendarView cView = new CalendarView(startDate, endDate, 50); cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id); FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
Navin.D http://dnavin.wordpress.com
Navin.D http://dnavin.wordpress.com
推荐答案
客户端程序提供的凭据无权访问资源,这是401错误的含义。
The credentials presented by the client program does not have authority to access the resource is what the 401 error means.
您可以向办公室论坛发帖寻求帮助。
You can post to the office forum for help.
https://social.msdn.microsoft.com/forums/office/en-us/home?category=officedev
https://social.msdn.microsoft.com/forums/office/en-us/home?category=officedev
这篇关于C#代码从O365获取用户的日历信息-Error远程服务器返回错误:(401)未经授权。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!