使用服务帐户访问其他用户日历

问题描述:

我们正在尝试使用EWS托管API集成Office 365.我们已经使用Office 365管理中心创建了一个具有模拟角色的服务帐户. 现在,我们如何使用该服务帐户访问应用程序中其他用户的数据(如邮件,联系人,日历)? 谢谢,罗希特(Rohit)

We are trying to integrate office 365 using EWS managed API's. We have created one service account with impersonation role using office 365 admin center. Now, how can we use that service account to access other user's data(like mails, contacts, calendar) in the application ? Thanks, Rohit

您照常创建ExchangeService的实例,然后设置其ImpersonatedUserId.

You create an instance of ExchangeService as usual and then set its ImpersonatedUserId.

示例:

var credentials = new WebCredentials(
    "impersonateduser@your.onmicrosoft.com", "password", "");

var exchange = new ExchangeService{PreAuthenticate=true, Credentials=credentials};
exchange.ImpersonatedUserId = new ImpersonatedUserId(
    ConnectingIdType.SmtpAddress, 
    "calendaruser@your.onmicrosoft.com");

此后,您可以访问其他用户(在本例中为calendaruser)的数据.

After this you can access the other user's (in this case calendaruser) data.