Truy xuất chỉ số email

Bạn có thể truy xuất chỉ số email cho một ngày cụ thể trên một miền cụ thể hoặc cho tất cả các ngày trên một miền cụ thể.

Để biết thông tin về cách cải thiện một số chỉ số nhất định, hãy tham khảo bài viết Ngăn chặn việc thư gửi đến người dùng Gmail bị chặn hoặc bị chuyển vào thư mục Thư rác

Truy xuất chỉ số cho một ngày cụ thể

Để truy xuất chỉ số cho một ngày cụ thể, hãy gọi hàm domains.trafficStats.get() theo miền và ngày. Sau đây là mã mẫu cho biết cách truy xuất chỉ số email cho một ngày cụ thể:

Java

/**
   * Gets the traffic stats for a domain for a specific date.
   *
   * @param service Authorized Gmail PostmasterTools API instance.
   * @param domainName The fully qualified domain name.
   * @param date The date to get the domain traffic stats. Must be in "YYYYMMDD" format.
   * @return The traffic stats of the domain for this date.
   * @throws IOException
   */
public static TrafficStats getTrafficStats(PostmasterTools service, String domainName, String date) throws IOException {
  String query = String.format("domains/%s/trafficStats/%s", domainName, date);
  TrafficStats trafficStats = service.domains().trafficStats().get(query).execute();
  System.out.println(trafficStats.toPrettyString());
  return trafficStats;
}

Python

"""Gets the traffic stats for a domain for a specific date.

  Args:
  service: Authorized Gmail PostmasterTools API instance.
  domain_name: The fully qualified domain name.
  date The date to get the domain traffic stats. Must be in "YYYYMMDD" format.

  Returns:
  The traffic stats of the domain for this date.
  """
def get_traffic_stats(service, domain_name, date):
    """Gets the traffic stats for a domain for a specific date.

  Args:
    service: Authorized Gmail PostmasterTools API instance.
    domain_name: The fully qualified domain name.
    date The date to get the domain traffic stats. Must be in "YYYYMMDD" format.

  Returns:
    The traffic stats of the domain for this date.
    """
    try:
        query = 'domains/%s/trafficStats/%s' %(domain_name,date)
        traffic_stats = service.domains().trafficStats().get(name=query).execute();
        print(traffic_stats);
        return traffic_stats;
    except errors.HttpError as err:
        print('An error occurred: %s' % err)

Nếu thành công, phần nội dung phản hồi sẽ chứa một thực thể của TrafficStats.

Truy xuất chỉ số cho tất cả các ngày

Để truy xuất các chỉ số cho tất cả các ngày, hãy gọi phương thức domains.trafficStats.list() theo miền. Sau đây là mã mẫu cho biết cách truy xuất chỉ số email cho tất cả các ngày:

Java

/**
   * Lists traffic statistics for all available days.
   *
   * @param service Authorized Gmail PostmasterTools API instance.
   * @param domainName The fully qualified domain name.
   * @param pageSize The number of TrafficStats to get per request.
   * @param pageToken The nextPageToken value returned from a previous List request, if any.
   * @return Response message for list traffic stats request.
   * @throws IOException
   */
public static ListTrafficStatsResponse listTrafficStats(PostmasterTools service, String domainName,
                                                      int pageSize,
                                                      String pageToken) throws IOException {
  ListTrafficStatsResponse listTrafficStatsResponse = service.domains().trafficStats().list("domains/" + domainName)
          .setPageSize(pageSize)
          .setPageToken(pageToken)
          .execute();
  System.out.println(listTrafficStatsResponse.toPrettyString());
  return null;
}

Python

"""Gets the traffic stats for a domain for a specific date.

  Args:
  service: Authorized Gmail PostmasterTools API instance.
  domain_name: The fully qualified domain name.
  date The date to get the domain traffic stats. Must be in "YYYYMMDD" format.
  page_size The number of TrafficStats to get per request.
  page_token The nextPageToken value returned from a previous List request, if any.

  Returns:
  The traffic stats of the domain for this date.
  """
def list_traffic_stats(service, domain_name, date, page_size, page_token):
  """Gets the traffic stats for a domain for a specific date.

    Args:
    service: Authorized Gmail PostmasterTools API instance.
    domain_name: The fully qualified domain name.
    date The date to get the domain traffic stats. Must be in "YYYYMMDD" format.
    page_size The number of TrafficStats to get per request.
    page_token The nextPageToken value returned from a previous List request, if any.

    Returns:
    The traffic stats of the domain for this date.
    """
    try:
        query = 'domains/' + domain_name
        list_traffic_stats_response = service.domains().trafficStats().list(parent=query, pageSize=page_size, pageToken=page_token).execute();
        print(list_traffic_stats_response);
        return list_traffic_stats_response;
    except errors.HttpError as err:
        print('An error occurred: %s' % err)

if __name__ == '__main__':
    main()

Nếu thành công, nội dung phản hồi sẽ chứa một mảng TrafficStats được phân trang theo cấu trúc như sau:

{
  "trafficStats": [
    {
      object (TrafficStats)
    }
  ],
  "nextPageToken": string
}