使用Java API从Outlook.com获取日历事件

问题描述:

我想使用Java API从Outlook.com获取所有日历事件。我测试了这个代码连接:使用Java API从Outlook.com获取日历事件

public void findChildFolders(String username, String password) throws Exception 
    { 
     ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); 
     ExchangeCredentials credentials = new WebCredentials(username, password); 

//  URI jira_url = URI.create("outlook.live.com"); 
     service.autodiscoverUrl(username, new RedirectionUrlCallback()); 
     service.setCredentials(credentials); 

     FindFoldersResults findResults = service.findFolders(WellKnownFolderName.Inbox, new FolderView(Integer.MAX_VALUE)); 

     for (Folder folder : findResults.getFolders()) 
     { 
      System.out.println("Count======" + folder.getChildFolderCount()); 
      System.out.println("Name=======" + folder.getDisplayName()); 
     } 
    } 

    static class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl 
    { 
     @Override 
     public boolean autodiscoverRedirectionUrlValidationCallback(
      String redirectionUrl) 
     { 
      return redirectionUrl.toLowerCase().startsWith("https://"); 
     } 
    } 

,但我得到错误堆栈:

microsoft.exchange.webservices.data.autodiscover.exception.AutodiscoverLocalException: The Autodiscover service couldn't be located. 
    at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.internalGetLegacyUserSettings(AutodiscoverService.java:742) 

什么是实现这个代码的正确方法?

获取房间资源日历的完整示例如下:Office365 API - Admin accessing another users/room's calendar events。您可以轻松地调整代码以获取来自经过身份验证的相同用户的日历活动,或者如果您的经过身份验证的用户拥有该权限,则可以获得其他用户/电子邮件/资源。