通过在浏览器中点击此请求:https ://outlook.office365.com/api/v1.0/users/room@email.com/events ,我可以输入我的管理员用户名和密码并获取该特定房间的日历事件。但是,当我尝试从经过管理员身份验证的本机应用程序进行此调用时,我收到以下响应: 原因 =“调用应访问 oauth 令牌中指定的邮箱。”;error_category =“invalid_grant” 如何获取日历事件特定房间被认证为管理员?
2 回答
目前我们只允许访问属于经过身份验证的用户的邮件、日历和联系人。因此,您的管理员访问 conf. 目前不支持房间日历。访问属于其他用户的资源,例如 conf。房间日历在我们的支持路线图上,但我们还没有与您分享的时间表。
与此同时,您有两个选择。
选项 #1:如果您能够在服务器上运行应用程序,则可以构建需要管理员同意但有权访问 Office 365 租户中的任何邮箱的服务应用程序。您需要让您的本机应用程序与服务器上运行的应用程序通信。有关更多详细信息,请参阅此博客。
选项 #2:您可以使用我们的 Exchange Web 服务 SOAP API 来实现您的场景。有关此选项和相关链接的更多详细信息,请参阅Office 365 共享日历。
这个小的 PLUG-N-COMPILE-RUN (woo-hoo!) Java 类应该演示如何获取房间资源用户事件日历。Azure V2.0 REST API 当前不允许这样做。确保向 Exchange 服务进行身份验证的 auth-user 是您要检索其事件的房间资源用户日历(或该日历的“代表”)。您的 Exchange/Office365 管理员可能需要为您进行设置。我在这里获取了 Java EWS API:Index of /maven2/com/microsoft/ews-java-api/ews-java-api/2.0/ews-java-api-2.0.jar和 javadoc.jar,这是一个很好的参考. 如果你去 Github repo,你也可以使用 Maven、Gradle 或其他方法将 API 集成到你的代码中:https ://github.com/OfficeDev/ews-java-api. 入门指南是……嗯……话让我无法理解(有充分的理由)。这么说吧,你最好稍微使用一下你的搜索引擎,以便弄清楚如何做其他事情!浏览 Javadoc 中的类对我有很大帮助。够了废话废话......关于代码:(哦,我包含了所有的导入!当我得到一个示例代码片段时我总是讨厌它,我不得不去寻找和啄食导入。我仍然不过,让你来连接实际的库!如果你能走到这一步,你就不再穿代码尿布了!;-)
package com.on.and.play
import java.net.URI;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.text.DateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat
import microsoft.exchange.webservices.data.core.service.item.Appointment;
import microsoft.exchange.webservices.data.core.service.schema.AppointmentSchema;
import microsoft.exchange.webservices.data.core.service.folder.CalendarFolder;
import microsoft.exchange.webservices.data.search.CalendarView;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.search.FindItemsResults;
import microsoft.exchange.webservices.data.property.complex.FolderId;
import microsoft.exchange.webservices.data.search.FolderView
import microsoft.exchange.webservices.data.core.service.schema.FolderSchema
import microsoft.exchange.webservices.data.search.FindFoldersResults
import microsoft.exchange.webservices.data.search.filter.SearchFilter
import microsoft.exchange.webservices.data.core.enumeration.search.FolderTraversal
import microsoft.exchange.webservices.data.core.service.item.Item;
import microsoft.exchange.webservices.data.core.service.schema.ItemSchema;
import microsoft.exchange.webservices.data.property.complex.Mailbox
import microsoft.exchange.webservices.data.search.ItemView;
import microsoft.exchange.webservices.data.core.PropertySet;
import microsoft.exchange.webservices.data.property.definition.PropertyDefinition
import microsoft.exchange.webservices.data.credential.WebCredentials;
import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
import microsoft.exchange.webservices.data.core.enumeration.property.BasePropertySet;
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException
import java.net.URI;
class MyTestService {
public List getRoomCalendar() {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
// replace somebodyreal@somewhere.com with a real email address that is
// a delegate of ConferenceRoom@somewhere.com. Your exchange admin may
// need to set that up for you.
ExchangeCredentials credentials
= new WebCredentials("somebodyreal@somewhere.com",
"their_plain_text_password_God_bless_Microsoft");
service.setCredentials(credentials);
service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx"));
// service.autodiscoverUrl("toddp@touchsource.com", );
FolderView fv = new FolderView(100);
fv.setTraversal(FolderTraversal.Deep);
// replace ConferenceRoom@somewhere.com with your resource's email address
FolderId confRoomFolderId = new FolderId(WellKnownFolderName.Calendar,
new Mailbox("ConferenceRoom@somewhere.com"));
List apntmtDataList = new ArrayList();
Calendar now = Calendar.getInstance();
Date startDate = Calendar.getInstance().getTime();
now.add(Calendar.DATE, 30);
Date endDate = now.getTime();
try {
CalendarFolder calendarFolder = CalendarFolder.bind(service, confRoomFolderId);
CalendarView cView = new CalendarView(startDate, endDate, 5);
cView.setPropertySet(new PropertySet(AppointmentSchema.Subject,
AppointmentSchema.Start,
AppointmentSchema.End));
// we can set other properties as well depending upon our need.
FindItemsResults appointments = calendarFolder.findAppointments(cView);
List<Appointment> appList = appointments.getItems();
for (Appointment appointment : appList) {
Map appointmentData = new HashMap();
appointmentData = readAppointment(appointment);
apntmtDataList.add(appointmentData);
}
} catch (Exception e) {
e.printStackTrace();
}
return apntmtDataList;
}
public Map readAppointment(Appointment appointment) {
Map appointmentData = new HashMap();
try {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
appointmentData.put("appointmentItemId", appointment.getId().toString());
appointmentData.put("appointmentSubject", appointment.getSubject());
appointmentData.put("appointmentStartTime", df.format(appointment.getStart()));
appointmentData.put("appointmentEndTime", df.format(appointment.getEnd()));
} catch (ServiceLocalException e) {
e.printStackTrace();
}
return appointmentData;
}
}