在没有 UI 的情况下使用 Office 365 REST API [英] Consume Office 365 REST API Without UI

查看:30
本文介绍了在没有 UI 的情况下使用 Office 365 REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将日历条目推送到客户的 Outlook 帐户.这对于 Exchange 来说是相当直接的.您只需向具有访问权限的用户进行身份验证,然后您就可以将条目推送到其他用户的帐户中.在 Office 365 中似乎完全不同.

I need to push calendar entries in to a client's Outlook account. This is fairly straight forward with Exchange. You just authenticate with a user that has access, and then you can push entries in to other user's accounts. It seems to be completely different in Office 365.

我尝试按照此处的说明进行操作:https://dev.outlook.com/restapi/getstarted

I tried to follow the instructions here: https://dev.outlook.com/restapi/getstarted

我创建了应用程序并获得了应用程序的客户端 ID.但是,所有文档都围绕 oAuth.一般来说,oAuth 适用于用户需要通过浏览器窗口输入凭据的场景,然后该浏览器窗口将与用户确认他们愿意允许应用拥有哪些凭据.

I created the app and got the app's client ID. But, all of the documentation is around oAuth. Generally speaking, oAuth is designed for scenarios when a user needs to enter their credentials in through a browser window that will then confirm with the user which credentials they are willing to allow the app to have.

这与我的场景不符.我需要能够在没有任何 UI 的情况下将日历条目推送到帐户中.这是后端集成.它只需要默默地完成它的工作.

This does not match my scenario. I need to be able to push the calendar entries in to the account without any UI. This is back end integration. It just needs to do its job silently.

我查看了这个示例应用:https://github.com/OfficeDev/O365-Win-Snippets

I looked at this sample app: https://github.com/OfficeDev/O365-Win-Snippets

但是,这是一个前端应用程序.当它需要进行身份验证时,它会弹出一个窗口,强制用户输入他们的凭据.

But, this is a front end app. When it needs to authenticate, it pops up a window to force the user to enter their credentials.

当我尝试调用入门页面中提到的 REST API 时,它返回 HTML.这是它提到的网址:

When I try to call the REST API that is mentioned in the getting started page, it returns HTML. This is the Url it mentions:

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

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 凭据.

I've tried a few permutations of this Url with my client ID. I've tried passing in my Office 365 credentials through basic http authentication.

我被卡住了.

推荐答案

答案很简单.使用 Exchange API - 而不是 Office 365 API.

The answer is simple. Use the Exchange API - not Office 365 API.

我很困惑,因为我认为 Office 365 是与 Exchange 不同的实体,但 Office 365 电子邮件服务器只是一个巨大的 Exchange 服务器.这里有一些示例代码可以很好地衡量.这是登录到 Office 365 的 Exchange 服务器并将日历条目发送到电子邮件地址的示例.简单.

I was confused because I assumed that Office 365 was a different entity to Exchange, but the Office 365 email server just is one giant Exchange server. Here's some sample code for good measure. This is an example of logging in to Office 365's Exchange server and sending off a calendar entry to an email address. Simple.

我对交换网址做了一个疯狂的猜测,它是正确的:https://outlook.office365.com/ews/exchange.asmx

I made a wild guess about the exchange Url and it was correct: 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); 

这篇关于在没有 UI 的情况下使用 Office 365 REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆