【问题标题】:Get an access to Office 365 API without UI [closed]无需 UI 即可访问 Office 365 API [关闭]
【发布时间】:2018-12-01 10:03:57
【问题描述】:

我需要编写一个 .NET Core 控制台应用程序,从 Office 365 帐户获取一些电子邮件。

是否有可能在没有任何弹出窗口和 UI 的情况下使用电子邮件和密码访问 Office 365 API?

我尝试了在 Azure Active Directory 中注册应用程序的解决方案,但它并不真正适合我的目的,因为登录的用户必须与特定的 AAD 帐户相关联。

我在 Stuck Overflow 上发现了这样的问题,但都与旧版本的 API 和旧方法有关。

我花了 4 天时间寻找解决方案并阅读了大量文档,但我仍然陷入困境。

【问题讨论】:

  • 这看起来很不错的文档示例:Get started with Office 365 Management APIs
  • @Reniuz,本文档介绍了将用户重定向到 Azure AD 网站以获取授权代码的选项。我不能使用这种方法
  • 您需要在 Office 365 Azure AD 中注册您的 API 并允许访问 Graph API。从那里,您可以创建和使用应用程序密钥来获取 Graph API 的访问令牌。
  • @Dusan,但它只适用于注册应用程序的用户,对吗?而且这个用户不能使用个人账号,只能工作/学习

标签: c# .net .net-core office365 asp.net-core-2.0


【解决方案1】:

以下示例使用的是 Exchange API,而不是 Office 365 API。

这是登录 Office 365 的 Exchange 服务器并将日历条目发送到电子邮件地址的示例。

//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); 

更多信息,请查看以下链接:

Consume Office 365 REST API Without UI

Get Office 365 API access token without user interaction

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 2012-05-04
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多