Office365 API - 管理员访问其他用户/房间的日历活动

时间:2015-06-02 11:06:18

标签: office365 outlook-restapi

点击此请求:https://outlook.office365.com/api/v1.0/users/room@email.com/events 在浏览器中,我可以输入我的管理员用户名和密码,并获取该特定房间的日历活动。 但是,当我尝试从管理员身份验证的本机应用程序进行此调用时,我收到此响应: reason =“呼叫应该访问oauth令牌中指定的邮箱。”; error_category =“invalid_grant” 如何获取以管理员身份验证的特定会议室的日历活动?

2 个答案:

答案 0 :(得分:5)

目前,我们只允许访问属于经过身份验证的用户的邮件,日历和联系人。所以,您的管理员访问conf的场景。目前不支持会议室日历。访问属于其他用户的资源,例如CONF。我们的路线图是支持房间日历,但我们还没有时间表与您分享。

与此同时,您有两种选择。

选项#1:如果您能够在服务器上运行该应用,则可以构建需要管理员同意的服务应用,但有权访问Office 365租户中的任何邮箱。您需要让本机应用程序与服务器上运行的应用程序通信。有关详细信息,请参阅此blog

选项#2:您可以使用我们的Exchange Web服务SOAP API来实现您的方案。有关此选项和相关链接的详细信息,请参阅Office 365 shared calendars

答案 1 :(得分:3)

这个小型的PLUG-N-COMPILE-RUN(woo-hoo!)Java类应该演示获取房间资源用户的事件日历。 Azure V2.0 REST API目前不允许这样做。确保对Exchange服务进行身份验证的auth-user是" delegate"到(或)要检索其事件的房间资源用户日历。您的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:https://github.com/OfficeDev/ews-java-api,您还可以使用Maven,Gradle或其他方法将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 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;
  }
}