概览

借助 Alert Center API,您可以管理影响您网域的 提醒。提醒是 Google 检测到的潜在安全问题的警告。提醒包含以下信息:

  • 提醒的来源。
  • 提醒的名称。
  • 此提醒发生的时间。
  • 与此提醒关联的特定数据。

网域管理员可以通过 Google 管理控制台手动查看和管理提醒。借助 Alert Center API,您构建的应用可以检索提醒数据和提醒反馈。 此 API 还可为现有提醒创建新的提醒反馈。

例如,监控应用可以使用 Alert Center API 检索针对网域的最新提醒,确定其优先顺序,然后通知组织成员。您的团队回复提醒后,应用便可以根据回复内容在提醒中附加反馈。

使用 Alert Center API

在使用 Alert Center API 之前,您需要设置 新的 Google Cloud 项目并启用 Alert Center API。您的 项目在访问 API 时必须使用服务账号

如果您的应用拥有满足前提条件且已获得 适当 授权的 Google 云项目,则可以 发出 Alert Center API REST 请求。使用可用的 客户端库 可以更轻松地发出 API 请求。

以下示例展示了如何使用 API 列出可用的提醒:

Java

// First, authorize the API and create a client to make requests with.
URL serviceAccountUrl = AuthUtils.class.getResource("/client_secret.json");
GoogleCredentials credentials =  ServiceAccountCredentials
    .fromStream(serviceAccountUrl.openStream())
    .createDelegated("admin@xxxx.com")
    .createScoped(Collections.singleton("https://www.googleapis.com/auth/apps.alerts"));
ApacheHttpTransport transport = new ApacheHttpTransport();
HttpCredentialsAdapter adapter = new HttpCredentialsAdapter(credentials);
AlertCenter alertCenter = new AlertCenter.Builder(transport, new JacksonFactory(), adapter)
    .setApplicationName("Alert Center client")
    .build();

// List alerts in pages, printing each alert discovered.
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);