總覽

您可以透過 Alert Center API 管理對網域的快訊。 警告代表 Google 偵測到潛在的安全性問題。 快訊包含下列資訊:

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

網域管理員可透過 Google 管理控制台查看及管理快訊。Alert Center API 可讓您建構的應用程式擷取快訊資料和快訊意見回饋。這個 API 也可以針對現有快訊建立新的快訊意見回饋。

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

使用 Alert Center API

使用 Alert Center API 前,您需要先設定新的 Cloud Platform 專案並啟用 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);