检索电子邮件指标

您可以检索特定网域上某一天或某天 。

如需了解如何提升某些指标,请参阅 防止发送给 Gmail 用户的邮件遭到屏蔽或被列为垃圾邮件

检索特定日期的指标

要检索特定日期的指标,请调用 domains.trafficStats.get() 域名和日期以下代码示例展示了如何检索 特定日期的电子邮件指标:

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)

如果成功,响应正文会包含一个 TrafficStats 实例。

检索所有日期的指标

要检索所有日期的指标,请调用 domains.trafficStats.list() 与域名相关联。以下代码示例展示了如何检索电子邮件 所有日期的指标:

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()

如果成功,响应正文将包含一个采用以下结构的 TrafficStats 分页数组:

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