← 返回目录
来源:Google Ads API 官方文档 · 中文版 · 本地归档

申请广告豁免

申请广告豁免的步骤如下:

  1. 存储包含在 PolicyTopicEntry(存储在 PolicyFindingDetails 中)中的所有可忽略的政策主题,这些主题是在您首次尝试更改广告失败时返回的。
  2. 发送 mutate 请求,以再次创建或更新广告,其中包含存储的可忽略政策主题。

在本指南中,我们将制作一个自适应搜索广告作为示例。申请豁免的步骤对于所有广告类型都是相同的,对于所有 mutate(创建和更新)操作都是类似的。

存储所有可忽略的政策主题

广告的错误详情包含在 PolicyFindingDetails 中,而 PolicyFindingDetails 又存储着 PolicyTopicEntry 对象的列表。

在此步骤中,您将存储每个 PolicyTopicEntry 的 topic 字段:

Java

private List<String> fetchIgnorablePolicyTopics(GoogleAdsException gae) {
  System.out.println("Google Ads failure details:");

  // Creates a list to store the result.
  List<String> ignorableTopics = new ArrayList<>();

  // Searches all errors for ignorable policy topics.
  for (GoogleAdsError error : gae.getGoogleAdsFailure().getErrorsList()) {
    // Supports sending exemption request for the policy finding error only.
    if (error.getErrorCode().getErrorCodeCase() != ErrorCodeCase.POLICY_FINDING_ERROR) {
      throw gae;
    }

    // Shows some information about the error encountered.
    System.out.printf("\t%s: %s%n", error.getErrorCode().getErrorCodeCase(), error.getMessage());

    // Checks policy finding details for ignorable policy topics.
    if (error.getDetails() != null) {
      PolicyFindingDetails policyFindingDetails = error.getDetails().getPolicyFindingDetails();
      if (policyFindingDetails != null) {
        System.out.println("\tPolicy finding details:");
        // Shows all the policy topics for the current error.
        for (PolicyTopicEntry policyTopicEntry :
            policyFindingDetails.getPolicyTopicEntriesList()) {
          // Adds this topic to the result.
          ignorableTopics.add(policyTopicEntry.getTopic());
          System.out.printf("\t\tPolicy topic name: '%s'%n", policyTopicEntry.getTopic());
          System.out.printf("\t\tPolicy topic entry type: '%s'%n", policyTopicEntry.getType());
          // For the sake of brevity, we exclude printing "policy topic evidences" and
          // "policy topic constraints" here. You can fetch those data by calling:
          // - policyTopicEntry.getEvidences()
          // - policyTopicEntry.getConstraints()
        }
      }
    }
  }
  return ignorableTopics;
}
      

C#

private static string[] FetchIgnorablePolicyTopics(GoogleAdsException ex)
{
    List<string> ignorablePolicyTopics = new List<string>(); ;

    Console.WriteLine("Google Ads failure details:");
    foreach (GoogleAdsError error in ex.Failure.Errors)
    {
        if (error.ErrorCode.ErrorCodeCase != ErrorCode.ErrorCodeOneofCase.PolicyFindingError)
        {
            throw ex;
        }
        if (error.Details != null && error.Details.PolicyFindingDetails != null)
        {
            PolicyFindingDetails details = error.Details.PolicyFindingDetails;
            Console.WriteLine($"- Policy finding details:");

            foreach (PolicyTopicEntry entry in details.PolicyTopicEntries)
            {
                ignorablePolicyTopics.Add(entry.Topic);
                Console.WriteLine($"  - Policy topic name: '{entry.Topic}'");
                Console.WriteLine($"  - Policy topic entry type: '{entry.Type}'");
                // For the sake of brevity, we exclude printing "policy topic evidences"
                // and "policy topic constraints" here. You can fetch those data by
                // calling:
                // - entry.Evidences
                // - entry.Constraints
            }
        }
    }
    return ignorablePolicyTopics.ToArray();
}
      

PHP

private static function fetchIgnorablePolicyTopics(GoogleAdsException $googleAdsException)
{
    $ignorablePolicyTopics = [];

    printf("Google Ads failure details:%s", PHP_EOL);
    foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
        /** @var GoogleAdsError $error */
        if ($error->getErrorCode()->getErrorCode() !== 'policy_finding_error') {
            // This example supports sending exemption request for the policy finding error
            // only.
            throw $googleAdsException;
        }

        printf(
            "\t%s: %s%s",
            $error->getErrorCode()->getErrorCode(),
            $error->getMessage(),
            PHP_EOL
        );
        if (
            !is_null($error->getDetails())
            && !is_null($error->getDetails()->getPolicyFindingDetails())
        ) {
            $policyFindingDetails = $error->getDetails()->getPolicyFindingDetails();
            printf("\tPolicy finding details:%s", PHP_EOL);

            foreach ($policyFindingDetails->getPolicyTopicEntries() as $policyTopicEntry) {
                /** @var PolicyTopicEntry $policyTopicEntry */
                $ignorablePolicyTopics[] = $policyTopicEntry->getTopic();
                printf(
                    "\t\tPolicy topic name: '%s'%s",
                    $policyTopicEntry->getTopic(),
                    PHP_EOL
                );
                printf(
                    "\t\tPolicy topic entry type: '%s'%s",
                    PolicyTopicEntryType::name($policyTopicEntry->getType()),
                    PHP_EOL
                );
                // For the sake of brevity, we exclude printing "policy topic evidences" and
                // "policy topic constraints" here. You can fetch those data by calling:
                // - $policyTopicEntry->getEvidences()
                // - $policyTopicEntry->getConstraints()
            }
        }
    }
    return $ignorablePolicyTopics;
}
在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →