0

I want to get all calendar events from Outlook.com using Java API. I tested this code to connect:

 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://");
        }
    }

But I get error stack:

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)

What is the proper way to implement this code?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

0

A full working example of obtaining a room resource calendar is here: Office365 API - Admin accessing another users/room's calendar events. You can easily adapt the code to obtain the calendar events from the same user that was authenticated, or another user/email/resource if your authenticated user has rights to it.

Community
  • 1
  • 1
Twelve24
  • 637
  • 7
  • 15