Using the Alert Center Java API

Getting credentials

adminSDK/alertcenter/quickstart/src/main/java/AdminSDKAlertCenterQuickstart.java
InputStream in = AdminSDKAlertCenterQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
  throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleCredentials credentials = ServiceAccountCredentials
    .fromStream(in)
    .createDelegated(delegatedAdminEmail)
    .createScoped(SCOPES);

Creating an instance of the client

adminSDK/alertcenter/quickstart/src/main/java/AdminSDKAlertCenterQuickstart.java
NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
AlertCenter service = new AlertCenter.Builder(transport, JSON_FACTORY,
    new HttpCredentialsAdapter(getCredentials(DELEGATED_ADMIN_EMAIL)))
    .setApplicationName(APPLICATION_NAME)
    .build();

Displaying all Alerts

adminSDK/alertcenter/quickstart/src/main/java/AdminSDKAlertCenterQuickstart.java
String pageToken = null;
do {
  ListAlertsResponse listResponse = service.alerts().list().setPageToken(pageToken)
      .setPageSize(20).execute();
  if (listResponse.getAlerts() != null) {
    for (Alert alert : listResponse.getAlerts()) {
      System.out.println(alert);
    }
  }
  pageToken = listResponse.getNextPageToken();
} while (pageToken != null);

Providing feedback on a given alert

adminSDK/alertcenter/quickstart/src/main/java/AdminSDKAlertCenterQuickstart.java
AlertFeedback newFeedback = new AlertFeedback();
newFeedback.setType("VERY_USEFUL");
AlertFeedback feedback = service.alerts().feedback().create(alertId, newFeedback).execute();
System.out.println(feedback);