Mel*_*per 5 .net c# oauth office365
我需要将日历条目推送到客户端的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% 2Fmail.read
我已尝试使用我的客户端ID对此Url进行了一些排列.我尝试通过基本的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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5792 次 |
| 最近记录: |