// Connect with the service and authenticate WebmasterToolsService service = new WebmasterToolsService("exampleCo-exampleApp-1"); try { service.setUserCredentials(USERNAME, PASSWORD); } catch (AuthenticationException e) { System.out.println("Username or password invalid"); return; }
// Retrieve messages feed MessagesFeed messages; try { URL feedUrl; if (USER_LANGUAGE == null) { feedUrl = new URL(MESSAGES_FEED_URI); } else { feedUrl = new URL(MESSAGES_FEED_URI + "?hl=" + USER_LANGUAGE); } messages = service.getFeed(feedUrl, MessagesFeed.class); } catch (IOException e) { System.out.println("There was a network error."); return; } catch (ServiceException e) { System.out.println("The service is not available."); return; }
// Print the messages feed System.out.println(messages.getTitle().getPlainText()); for (MessageEntry entry : messages.getEntries()) { if (entry.getRead()) { System.out.print(" \t"); } else { System.out.print("new\t"); } System.out.print(entry.getDate().toUiString() + "\t"); System.out.println(entry.getSubject()); }