2

我可以使用下面的代码在我的组织中获得可用的会议室,我需要预约特定房间,所以我使用了下面的代码。`

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    static ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
    ExchangeCredentials credentials = new WebCredentials("xxx@yy.com", "zzzz");
    service.setCredentials(credentials);
    try {
        System.out.println("Check");
        service.autodiscoverUrl("xxx@yy.com",new RedirectionUrlCallback());



    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    NameResolutionCollection nameResolutions = service.resolveName("MeetingRoom1",ResolveNameSearchLocation.DirectoryOnly, true);
    System.out.println("nameResolutions==="+nameResolutions.getCount());

    for(NameResolution nameResolution : nameResolutions)
    {
        System.out.println("NAME==="+nameResolution.getContact().getDisplayName());


    }
    Date startDate = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(startDate);
    cal.add(Calendar.DATE, 30); // add 10 days

    Date endDate = cal.getTime();
       Mailbox meetingMailbox = new Mailbox("meetingroom-1@yy.com");
       FolderId CalendarId = new FolderId(WellKnownFolderName.Calendar, meetingMailbox);
       CalendarView cView = new CalendarView(startDate, endDate);
       FindItemsResults<Appointment> appointments = service.findAppointments(CalendarId, cView);
       for (Appointment a : appointments)
       {
           System.out.println("Subject: " + a.getSubject().toString() + " ");
           System.out.println("Start: " + a.getStart().toString() + " ");
           System.out.println("End: " + a.getEnd().toString());
           System.out.println();
       }
}`

如果我执行此代码,我可以获得我的组织中名称为 MeetingRoom1 的所有可用会议室的列表,然后我尝试访问特定的 meetingroom-1@yy.com 以获取该房间的约会,但抛出一些例外,如下所示。

Exception in thread "main" microsoft.exchange.webservices.data.ServiceResponseException: The specified folder could not be found in the store.
at microsoft.exchange.webservices.data.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:262)
at microsoft.exchange.webservices.data.ServiceResponse.throwIfNecessary(ServiceResponse.java:251)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:146)
at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:807)
at microsoft.exchange.webservices.data.ExchangeService.findAppointments(ExchangeService.java:1089)
at com.hcl.GetRoomClass.main(GetRoomClass.java:58)

我想这可能是因为我没有访问会议室日历的访问权限。如何进一步进行预约。请帮助我。我在 EWS-JAVA API 中需要它。

提前致谢。

4

1 回答 1

2

运行您的代码的帐户需要委派访问会议室日历的权限才能使该代码正常工作。这是您的管理员需要在服务器上为您配置的内容。

于 2015-02-23T15:03:10.533 回答