특정 날짜의 측정항목을 가져오려면 도메인과 날짜를 사용하여 domains.trafficStats.get()를 호출합니다. 다음은 특정 날짜의 이메일 측정항목을 가져오는 방법을 보여주는 코드 샘플입니다.
자바
/** * 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 */publicstaticTrafficStatsgetTrafficStats(PostmasterToolsservice,StringdomainName,Stringdate)throwsIOException{Stringquery=String.format("domains/%s/trafficStats/%s",domainName,date);TrafficStatstrafficStats=service.domains().trafficStats().get(query).execute();System.out.println(trafficStats.toPrettyString());returntrafficStats;}
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. """defget_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);returntraffic_stats;excepterrors.HttpErroraserr:print('An error occurred: %s'%err)
/** * 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 */publicstaticListTrafficStatsResponselistTrafficStats(PostmasterToolsservice,StringdomainName,intpageSize,StringpageToken)throwsIOException{ListTrafficStatsResponselistTrafficStatsResponse=service.domains().trafficStats().list("domains/"+domainName).setPageSize(pageSize).setPageToken(pageToken).execute();System.out.println(listTrafficStatsResponse.toPrettyString());returnnull;}
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. """deflist_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_namelist_traffic_stats_response=service.domains().trafficStats().list(parent=query,pageSize=page_size,pageToken=page_token).execute();print(list_traffic_stats_response);returnlist_traffic_stats_response;excepterrors.HttpErroraserr:print('An error occurred: %s'%err)if__name__=='__main__':main()
성공하면 응답 본문에 다음과 같은 구조의 TrafficStats의 페이지로 구분된 배열이 포함됩니다.
[null,null,["최종 업데이트: 2025-08-29(UTC)"],[],[],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 }"]]