เรียกข้อมูลสถิติอีเมล

คุณสามารถดึงข้อมูลสถิติอีเมลสำหรับช่วงวันที่ที่เฉพาะเจาะจงในโดเมนที่เฉพาะเจาะจงได้

ดูข้อมูลเกี่ยวกับวิธีปรับปรุงสถิติบางรายการได้ที่ หัวข้อป้องกันไม่ให้ระบบบล็อกหรือนำอีเมลที่ส่งหาผู้ใช้ Gmail ไปยังจดหมายขยะ

หมายเหตุ: หากไม่เห็นค่าของสถิติบางรายการ แสดงว่าคุณอาจส่งอีเมลรายวันไม่เพียงพอ เฉพาะโดเมนที่ส่งอีเมลถึงผู้ใช้รายวันอย่างน้อย 50 รายเท่านั้นที่จะได้รับสถิติ ดูข้อมูลเพิ่มเติมได้ที่ คำถามที่พบบ่อยเกี่ยวกับ Postmaster Tools

ดึงข้อมูลสถิติสำหรับช่วงวันที่

หากต้องการดึงข้อมูลสถิติสำหรับช่วงวันที่ที่เฉพาะเจาะจง ให้เรียกใช้ domains.domainStats.query() พร้อมกับโดเมนและช่วงวันที่ ด้านล่างนี้คือตัวอย่างโค้ดที่แสดงวิธีดึงข้อมูลสถิติอีเมลสำหรับช่วงวันที่ที่เฉพาะเจาะจง

Java

/**
 * Lists domain statistics for a specific date range.
 *
 * @param service Authorized Gmail PostmasterTools API instance.
 * @param domainName The fully qualified domain name.
 * @param startDate The first day of the date range to retrieve statistics.
 * @param endDate The last day of the date range to retrieve statistics.
 * @param pageSize The number of DomainStats to get per request.
 * @param pageToken The nextPageToken value from a previous List request,
 *     if any.
 * @return Response message for query domain stats request.
 * @throws IOException
 */
public static QueryDomainStatsResponse queryDomainStats(
    PostmasterTools service, String domainName, Date startDate, Date endDate,
    int pageSize, String pageToken) throws IOException {
  QueryDomainStatsResponse queryDomainStatsResponse =
      service.domains().domainStats()
          .query("domains/" + domainName)
          .setStartDate(startDate)
          .setEndDate(endDate)
          .setPageSize(pageSize)
          .setPageToken(pageToken)
          .execute();
  System.out.println(queryDomainStatsResponse.toPrettyString());
  return queryDomainStatsResponse;
}

Python

def query_domain_stats(service, domain_name, start_date, end_date,
                       page_size, page_token):
  """Queries the domain stats for a domain for a specific date range.

  Args:
    service: Authorized Gmail PostmasterTools API instance.
    domain_name: The fully qualified domain name.
    start_date: The first day of the date range to retrieve statistics.
    end_date: The last day of the date range to retrieve statistics.
    page_size: The number of DomainStats to get per request.
    page_token: The nextPageToken value from a previous List request, if any.

  Returns:
    The domain stats of the domain for this date range.
  """
  try:
    query = 'domains/' + domain_name
    query_domain_stats_response = service.domains().domainStats().query(
        parent=query,
        startDate=start_date,
        endDate=end_date,
        pageSize=page_size,
        pageToken=page_token).execute()
    print(query_domain_stats_response)
    return query_domain_stats_response
  except errors.HttpError as err:
    print(f'An error occurred: {err}')

หากทำสำเร็จ เนื้อหาการตอบกลับจะมีอาร์เรย์ที่แบ่งหน้าของ DomainStat ซึ่งมีโครงสร้างดังต่อไปนี้

{
  "domainStats": [
    {
      object (DomainStat)
    }
  ],
  "nextPageToken": string
}

ดึงข้อมูลสถานะการปฏิบัติตามข้อกำหนดของโดเมน

หากต้องการดึงข้อมูลสถานะการปฏิบัติตามข้อกำหนดของโดเมน ให้เรียกใช้ domains.getComplianceStatus() พร้อมกับโดเมน สถานะการปฏิบัติตามข้อกำหนดจะมีข้อมูลการปฏิบัติตามข้อกำหนดสำหรับ Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM) และ Domain-based Message Authentication, Reporting, and Conformance (DMARC) ด้านล่างนี้คือตัวอย่างโค้ดที่แสดงวิธีดึงข้อมูลสถานะการปฏิบัติตามข้อกำหนดของโดเมน

Java

/**
 * Gets the compliance status for a domain.
 *
 * @param service Authorized Gmail PostmasterTools API instance.
 * @param domainName The fully qualified domain name.
 * @return The compliance status of the domain.
 * @throws IOException
 */
public static DomainComplianceStatus getComplianceStatus(
    PostmasterTools service, String domainName) throws IOException {
  String query = String.format("domains/%s/complianceStatus", domainName);
  DomainComplianceStatus complianceStatus =
      service.domains().getComplianceStatus(query).execute();
  System.out.println(complianceStatus.toPrettyString());
  return complianceStatus;
}

Python

def get_compliance_status(service, domain_name):
  """Gets the compliance status for a domain.

  Args:
    service: Authorized Gmail PostmasterTools API instance.
    domain_name: The fully qualified domain name.

  Returns:
    The compliance status of the domain.
  """
  try:
    query = 'domains/%s/complianceStatus' % domain_name
    compliance_status = service.domains().getComplianceStatus(
        name=query).execute()
    print(compliance_status)
    return compliance_status
  except errors.HttpError as err:
    print(f'An error occurred: {err}')

หากทำสำเร็จ เนื้อหาการตอบกลับจะมีอินสแตนซ์ของ DomainComplianceStatus