使用没有UI的Office 365 REST API [英] Consume Office 365 REST API Without UI

查看:122
本文介绍了使用没有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对这个网址进行一些排列.我尝试通过基本的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天全站免登陆