我正在尝试取消未取消的日历会议,但我收到的错误请求已超时。我只在我的本地机器上运行它。请指教。
ExchangeService service = new ExchangeService();
service.setTraceEnabled(true);
service.setUseDefaultCredentials(true);
service.setTraceEnabled(true);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = formatter.parse("2015-01-01 00:00:00");
Date endDate = formatter.parse("2015-01-10 23:59:59");
try{
service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx"));
CalendarFolder cal = CalendarFolder.bind(service, WellKnownFolderName.Calendar);
CalendarView calendarView = new CalendarView(startDate, startDate);
FindItemsResults<Appointment> findResults = cal.findAppointments(calendarView);
for (Appointment appt : findResults.getItems()) {
System.out.println("SUBJECT====="+appt.getSubject());
System.out.println("BODY========"+appt.getBody());
}
} catch (Exception e)
{
e.printStackTrace();
} // microsoft.exchange.webservices.data.exceptions.ServiceRequestException: The request failed. Connection timed out: connect caused by Caused by: java.net.ConnectException: Connection timed out: connect
答案 0 :(得分:0)
您无法对Office 365使用默认凭据,您需要指定它们。删除行:
service.setUseDefaultCredentials(true);
并将其替换为:
string username = "YOUR OFFICE365 EMAIL ADDRESS";
string password = "YOUR PASSWORD";
service.Credentials = new NetworkCredential(username, password);