2015-04-15 59 views
0

我正在嘗試提取未取消的日曆會議,但發現錯誤請求已超時。我只在我的本地機器上運行它。請指教。使用EWS提取會議

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

聯繫您的IT部門,並確保您可以訪問互聯網,並獲得任何必要的代理服務器,這樣做說明。 –

+0

嗨我可以在我的網絡瀏覽器中正常訪問辦公室360。我在想這是否是防火牆問題。但是我的代碼沒有錯,對嗎? – James

回答

0

您不能在Office 365上使用默認憑據,您需要指定它們。刪除行:

service.setUseDefaultCredentials(true); 

,取而代之的是:

string username = "YOUR OFFICE365 EMAIL ADDRESS"; 
string password = "YOUR PASSWORD"; 
service.Credentials = new NetworkCredential(username, password); 
+0

我收到此錯誤 – James

+0

microsoft.exchange.webservices.data.ServiceLocalException:https://outlook.office365.com/EWS/Exchange.asmx:連接錯誤 – James