درخواست معافیت برای کلمات کلیدی

برای درخواست معافیت برای کلمات کلیدی:

  1. تمام کلیدهای نقض خط‌مشی معاف موجود در PolicyViolationDetails را ذخیره کنید، که وقتی اولین تلاش شما برای ایجاد یک کلمه کلیدی با شکست مواجه می‌شود، بازگردانده می‌شود.
  2. یک درخواست جهش ارسال کنید تا با گنجاندن کلیدهای نقض خط‌مشی معاف ذخیره‌شده، کلمه کلیدی را دوباره ایجاد کنید.

تمام کلیدهای نقض خط‌مشی معاف را ذخیره کنید

جزئیات خطا برای کلمات کلیدی در PolicyViolationDetails گنجانده شده است، که به نوبه خود فیلد key را که مقدار آن یک شیء از PolicyViolationKey است، ذخیره می‌کند.

تمام کلیدهای نقض خط‌مشی معاف را برای استفاده در مرحله بعدی جمع‌آوری کنید:

جاوا

private List<PolicyViolationKey> extractExemptiblePolicyViolationKeys(
    GoogleAdsException googleAdsException) {
  List<PolicyViolationKey> exemptibleKeys = new ArrayList<>();
  System.out.println("Google Ads failure details:");
  for (GoogleAdsError googleAdsError : googleAdsException.getGoogleAdsFailure().getErrorsList()) {
    System.out.printf("\t%s: %s%n", googleAdsError.getErrorCode(), googleAdsError.getMessage());
    if (googleAdsError.hasDetails() && googleAdsError.getDetails().hasPolicyViolationDetails()) {
      PolicyViolationDetails policyViolationDetails =
          googleAdsError.getDetails().getPolicyViolationDetails();
      System.out.println("\tPolicy violation details:");
      System.out.printf(
          "\t\tExternal policy name: '%s'%n", policyViolationDetails.getExternalPolicyName());
      System.out.printf(
          "\t\tExternal policy description: '%s'%n",
          policyViolationDetails.getExternalPolicyDescription());
      System.out.printf("\t\tIs exemptible? '%s'%n", policyViolationDetails.getIsExemptible());
      if (policyViolationDetails.getIsExemptible() && policyViolationDetails.hasKey()) {
        PolicyViolationKey policyViolationKey = policyViolationDetails.getKey();
        exemptibleKeys.add(policyViolationKey);
        System.out.println("\t\tPolicy violation key:");
        System.out.printf("\t\t\tName: '%s'%n", policyViolationKey.getPolicyName());
        System.out.printf("\t\t\tViolating text: '%s'%n", policyViolationKey.getViolatingText());
      }
    }
  }
  return exemptibleKeys;
}
      

سی شارپ

private static PolicyViolationKey[] FetchExemptPolicyViolationKeys(GoogleAdsException ex)
{
    bool isFullyExemptable = true;
    List<PolicyViolationKey> exemptPolicyViolationKeys = new List<PolicyViolationKey>();

    Console.WriteLine("Google Ads failure details:");
    foreach (GoogleAdsError error in ex.Failure.Errors)
    {
        if (error.ErrorCode.ErrorCodeCase !=
            ErrorCode.ErrorCodeOneofCase.PolicyViolationError)
        {
            Console.WriteLine("No exemption request is sent because there are other " +
                "non-policy related errors thrown.");
            throw ex;
        }
        if (error.Details != null && error.Details.PolicyViolationDetails != null)
        {
            PolicyViolationDetails details = error.Details.PolicyViolationDetails;
            Console.WriteLine($"- Policy violation details:");

            Console.WriteLine(" - Policy violation details:");
            Console.WriteLine($"   - External policy name: '{details.ExternalPolicyName}'");
            Console.WriteLine($"   - External policy description: " +
                $"'{details.ExternalPolicyDescription}'");
            Console.WriteLine($"   - Is exemptable: '{details.IsExemptible}'");

            if (details.IsExemptible && details.Key != null)
            {
                PolicyViolationKey key = details.Key;
                Console.WriteLine($"   - Policy violation key:");
                Console.WriteLine($"     - Name: {key.PolicyName}");
                Console.WriteLine($"     - Violating Text: {key.ViolatingText}");
                exemptPolicyViolationKeys.Add(key);
            }
            else
            {
                isFullyExemptable = false;
            }
        }
    }

    if (!isFullyExemptable)
    {
        Console.WriteLine("No exemption request is sent because your keyword " +
            "contained some non-exemptible policy violations.");
        throw ex;
    }
    return exemptPolicyViolationKeys.ToArray();
}
      

پی اچ پی

private static function fetchExemptPolicyViolationKeys(GoogleAdsException $googleAdsException)
{
    $exemptPolicyViolationKeys = [];

    printf("Google Ads failure details:%s", PHP_EOL);
    foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
        /** @var GoogleAdsError $error */
        printf(
            "\t%s: %s%s",
            $error->getErrorCode()->getErrorCode(),
            $error->getMessage(),
            PHP_EOL
        );
        if (
            !is_null($error->getDetails())
            && !is_null($error->getDetails()->getPolicyViolationDetails())
        ) {
            $policyViolationDetails = $error->getDetails()->getPolicyViolationDetails();
            printf("\tPolicy violation details:%s", PHP_EOL);
            printf(
                "\t\tExternal policy name: '%s'%s",
                $policyViolationDetails->getExternalPolicyName(),
                PHP_EOL
            );
            printf(
                "\t\tExternal policy description: '%s'%s",
                $policyViolationDetails->getExternalPolicyDescription(),
                PHP_EOL
            );
            printf(
                "\t\tIs exemptible? '%s'%s",
                $policyViolationDetails->getIsExemptible() ? 'yes' : 'no',
                PHP_EOL
            );

            if (
                $policyViolationDetails->getIsExemptible() &&
                !is_null($policyViolationDetails->getKey())
            ) {
                $policyViolationDetailsKey = $policyViolationDetails->getKey();
                $exemptPolicyViolationKeys[] = $policyViolationDetailsKey;
                printf("\t\tPolicy violation key:%s", PHP_EOL);
                printf(
                    "\t\t\tName: '%s'%s",
                    $policyViolationDetailsKey->getPolicyName(),
                    PHP_EOL
                );
                printf(
                    "\t\t\tViolating text: '%s'%s",
                    $policyViolationDetailsKey->getViolatingText(),
                    PHP_EOL
                );
            } else {
                print "No exemption request is sent because your keyword contained some "
                    . "non-exemptible policy violations." . PHP_EOL;
                throw $googleAdsException;
            }
        } else {
            print "No exemption request is sent because there are other non-policy related "
                . "errors thrown." . PHP_EOL;
            throw $googleAdsException;
        }
    }
    return $exemptPolicyViolationKeys;
}