检索电子邮件指标
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以检索特定网域上特定日期的电子邮件指标,也可以检索特定网域上所有日期的电子邮件指标。
如需了解如何改进某些指标,请参阅防止发送给 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
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Retrieve email metrics\n\nYou can retrieve email metrics for a specific day on a specific domain or for\nall days on a specific domain.\n\nFor information on how to improve certain metrics, refer to\n[Prevent mail to Gmail users from being blocked or sent to spam](https://support.google.com/mail/answer/81126)\n| **Note:** If you do not see values for some metrics, it's possible you do not send enough daily email. Only domains that send mail to at least 50 users per day receive metrics. For further information, refer to the [Postmaster Tools FAQ](https://support.google.com/mail/answer/6258950).\n\nRetrieve metrics for a specific day\n-----------------------------------\n\nTo retrieve metrics for a specific day, call\n[`domains.trafficStats.get()`](/workspace/gmail/postmaster/reference/rest/v1/domains.trafficStats/get)\nwith the domain and day. Following is a code sample showing how to retrieve\nemail metrics for a specific day: \n\n### Java\n\n /**\n * Gets the traffic stats for a domain for a specific date.\n *\n * @param service Authorized Gmail PostmasterTools API instance.\n * @param domainName The fully qualified domain name.\n * @param date The date to get the domain traffic stats. Must be in \"YYYYMMDD\" format.\n * @return The traffic stats of the domain for this date.\n * @throws IOException\n */\n public static TrafficStats getTrafficStats(PostmasterTools service, String domainName, String date) throws IOException {\n String query = String.format(\"domains/%s/trafficStats/%s\", domainName, date);\n TrafficStats trafficStats = service.domains().trafficStats().get(query).execute();\n System.out.println(trafficStats.toPrettyString());\n return trafficStats;\n }\n\n### Python\n\n \"\"\"Gets the traffic stats for a domain for a specific date.\n\n Args:\n service: Authorized Gmail PostmasterTools API instance.\n domain_name: The fully qualified domain name.\n date The date to get the domain traffic stats. Must be in \"YYYYMMDD\" format.\n\n Returns:\n The traffic stats of the domain for this date.\n \"\"\"\n def get_traffic_stats(service, domain_name, date):\n \"\"\"Gets the traffic stats for a domain for a specific date.\n\n Args:\n service: Authorized Gmail PostmasterTools API instance.\n domain_name: The fully qualified domain name.\n date The date to get the domain traffic stats. Must be in \"YYYYMMDD\" format.\n\n Returns:\n The traffic stats of the domain for this date.\n \"\"\"\n try:\n query = 'domains/%s/trafficStats/%s' %(domain_name,date)\n traffic_stats = service.domains().trafficStats().get(name=query).execute();\n print(traffic_stats);\n return traffic_stats;\n except errors.HttpError as err:\n print('An error occurred: %s' % err)\n\nIf successful, the response body contains an instance of [`TrafficStats`](/workspace/gmail/postmaster/reference/rest/v1/domains.trafficStats#TrafficStats).\n\nRetrieve metrics for all days\n-----------------------------\n\nTo retrieve metrics for all days, call\n[`domains.trafficStats.list()`](/workspace/gmail/postmaster/reference/rest/v1/domains.trafficStats/list)\nwith the domain. Following is a code sample showing how to retrieve email\nmetrics for all days: \n\n### Java\n\n /**\n * Lists traffic statistics for all available days.\n *\n * @param service Authorized Gmail PostmasterTools API instance.\n * @param domainName The fully qualified domain name.\n * @param pageSize The number of TrafficStats to get per request.\n * @param pageToken The nextPageToken value returned from a previous List request, if any.\n * @return Response message for list traffic stats request.\n * @throws IOException\n */\n public static ListTrafficStatsResponse listTrafficStats(PostmasterTools service, String domainName,\n int pageSize,\n String pageToken) throws IOException {\n ListTrafficStatsResponse listTrafficStatsResponse = service.domains().trafficStats().list(\"domains/\" + domainName)\n .setPageSize(pageSize)\n .setPageToken(pageToken)\n .execute();\n System.out.println(listTrafficStatsResponse.toPrettyString());\n return null;\n }\n\n### Python\n\n \"\"\"Gets the traffic stats for a domain for a specific date.\n\n Args:\n service: Authorized Gmail PostmasterTools API instance.\n domain_name: The fully qualified domain name.\n date The date to get the domain traffic stats. Must be in \"YYYYMMDD\" format.\n page_size The number of TrafficStats to get per request.\n page_token The nextPageToken value returned from a previous List request, if any.\n\n Returns:\n The traffic stats of the domain for this date.\n \"\"\"\n def list_traffic_stats(service, domain_name, date, page_size, page_token):\n \"\"\"Gets the traffic stats for a domain for a specific date.\n\n Args:\n service: Authorized Gmail PostmasterTools API instance.\n domain_name: The fully qualified domain name.\n date The date to get the domain traffic stats. Must be in \"YYYYMMDD\" format.\n page_size The number of TrafficStats to get per request.\n page_token The nextPageToken value returned from a previous List request, if any.\n\n Returns:\n The traffic stats of the domain for this date.\n \"\"\"\n try:\n query = 'domains/' + domain_name\n list_traffic_stats_response = service.domains().trafficStats().list(parent=query, pageSize=page_size, pageToken=page_token).execute();\n print(list_traffic_stats_response);\n return list_traffic_stats_response;\n except errors.HttpError as err:\n print('An error occurred: %s' % err)\n\n if __name__ == '__main__':\n main()\n\nIf successful, the response body contains a paginated array of [`TrafficStats`](/workspace/gmail/postmaster/reference/rest/v1/domains.trafficStats#TrafficStats) with the following structure: \n\n {\n \"trafficStats\": [\n {\n object (TrafficStats)\n }\n ],\n \"nextPageToken\": string\n }"]]