我需要将日历条目推入客户的Outlook帐户。对于Exchange,这是相当简单的。您只需向具有访问权限的用户进行身份验证,然后就可以将条目推入其他用户的帐户中。在Office 365中似乎完全不同。
我尝试按照此处的说明进行操作:https : //dev.outlook.com/restapi/getstarted
我创建了该应用程序,并获得了该应用程序的客户端ID。但是,所有文档都围绕oAuth。一般而言,oAuth是针对以下情况设计的:用户需要通过浏览器窗口输入其凭据,然后浏览器窗口将与用户确认他们愿意允许该应用拥有的凭据。
这与我的情况不符。我需要能够在没有任何UI的情况下将日历条目推入帐户。这是后端集成。它只需要默默地完成工作。
我看了这个示例应用程序:https : //github.com/OfficeDev/O365-Win-Snippets
但是,这是一个前端应用程序。当需要验证时,它会弹出一个窗口,以强制用户输入其凭据。
当我尝试调用入门页面中提到的REST API时,它将返回HTML。这是它提到的网址:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=&redirect_uri = http%3A%2F%2Flocalhost%2Fmyapp%2F&response_type = code&scope = https%3A%2F%2Foutlook.office.com% 2 Fmail.read
我已经尝试使用我的客户ID对这个网址进行一些排列。我尝试通过基本的HTTP身份验证传递Office 365凭据。
我被卡住了。
答案很简单。使用Exchange API-而不是Office 365 API。
我感到困惑是因为我认为Office 365是与Exchange不同的实体,但是Office 365电子邮件服务器只是一台巨型Exchange服务器。这是一些很好的示例代码。这是登录Office 365的Exchange服务器并将日历项发送到电子邮件地址的示例。简单。
我对交换网址做出了疯狂的猜测,它是正确的:https : //outlook.office365.com/ews/exchange.asmx
//Connect to exchange
var ewsProxy = new ExchangeService(ExchangeVersion.Exchange2013);
ewsProxy.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
//Create the meeting
var meeting = new Appointment(ewsProxy);
ewsProxy.Credentials = new NetworkCredential(_Username, _Password);
meeting.RequiredAttendees.Add(_Recipient);
// Set the properties on the meeting object to create the meeting.
meeting.Subject = "Meeting";
meeting.Body = "Please go to the meeting.";
meeting.Start = DateTime.Now.AddHours(1);
meeting.End = DateTime.Now.AddHours(2);
meeting.Location = "Location";
meeting.ReminderMinutesBeforeStart = 60;
// Save the meeting to the Calendar folder and send the meeting request.
meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句