總覽

Alert Center API 可讓您管理影響網域的快訊。 快訊是指 Google 偵測到潛在安全性問題的警告。 快訊包含下列資訊:

  • 快訊的來源。
  • 快訊名稱。
  • 這則快訊發生的時間。
  • 與這則快訊相關的特定資料。

網域管理員可透過 Google 管理控制台手動查看及管理快訊。透過 Alert Center API,應用程式可以擷取快訊資料和快訊意見回饋。API 也可以為現有快訊建立新的快訊意見回饋。

舉例來說,監控應用程式可以使用 Alert Center API 擷取網域最新的快訊、排定快訊的優先順序,然後通知機構成員。您的團隊回覆快訊後,應用程式就能根據結果,在快訊中附加意見回饋。

使用 Alert Center API

您必須先設定新的 Cloud Platform 專案並啟用 Alert Center API,才能使用 Alert Center API。您的專案必須使用服務帳戶存取 API。

只要應用程式的 Cloud 專案符合必要條件,並且獲得適當的授權,就能發出 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);