Search in sources :

Example 1 with AdGroupAdPolicySummary

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary in project googleads-java-lib by googleads.

the class GetAllDisapprovedAds method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to search for disapproved ads.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.PolicySummary).orderAscBy(AdGroupAdField.Id).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).equals(AdGroupAdField.CombinedApprovalStatus, PolicyApprovalStatus.DISAPPROVED.toString()).offset(offset).limit(PAGE_SIZE).build();
    // Get all disapproved ads.
    AdGroupAdPage page = null;
    int disapprovedAdsCount = 0;
    do {
        page = adGroupAdService.get(selector);
        // Display ads.
        for (AdGroupAd adGroupAd : page) {
            disapprovedAdsCount++;
            AdGroupAdPolicySummary policySummary = adGroupAd.getPolicySummary();
            System.out.printf("Ad with ID %d and type '%s' was disapproved with the following " + "policy topic entries:%n", adGroupAd.getAd().getId(), adGroupAd.getAd().getAdType());
            // Display the policy topic entries related to the ad disapproval.
            for (PolicyTopicEntry policyTopicEntry : policySummary.getPolicyTopicEntries()) {
                System.out.printf("  topic id: %s, topic name: '%s', Help Center URL: %s%n", policyTopicEntry.getPolicyTopicId(), policyTopicEntry.getPolicyTopicName(), policyTopicEntry.getPolicyTopicHelpCenterUrl());
                // Display the attributes and values that triggered the policy topic.
                if (policyTopicEntry.getPolicyTopicEvidences() != null) {
                    for (PolicyTopicEvidence evidence : policyTopicEntry.getPolicyTopicEvidences()) {
                        System.out.printf("    evidence type: %s%n", evidence.getPolicyTopicEvidenceType());
                        if (evidence.getEvidenceTextList() != null) {
                            for (int i = 0; i < evidence.getEvidenceTextList().length; i++) {
                                System.out.printf("      evidence text[%d]: %s%n", i, evidence.getEvidenceTextList(i));
                            }
                        }
                    }
                }
            }
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
    System.out.printf("%d disapproved ads were found.%n", disapprovedAdsCount);
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) PolicyTopicEvidence(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEvidence) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) PolicyTopicEntry(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEntry) AdGroupAdPolicySummary(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 2 with AdGroupAdPolicySummary

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary in project googleads-java-lib by googleads.

the class GetAllDisapprovedAdsWithAwql method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to search for disapproved ads.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(AdGroupAdField.Id, AdGroupAdField.PolicySummary).where(AdGroupAdField.AdGroupId).equalTo(adGroupId).where(AdGroupAdField.CombinedApprovalStatus).equalTo(PolicyApprovalStatus.DISAPPROVED.getValue()).orderBy(AdGroupAdField.Id, SortOrder.ASCENDING).limit(0, PAGE_SIZE).build();
    // Get all disapproved ads.
    AdGroupAdPage page = null;
    int disapprovedAdsCount = 0;
    do {
        serviceQuery.nextPage(page);
        page = adGroupAdService.query(serviceQuery.toString());
        // Display ads.
        for (AdGroupAd adGroupAd : page) {
            disapprovedAdsCount++;
            AdGroupAdPolicySummary policySummary = adGroupAd.getPolicySummary();
            System.out.printf("Ad with ID %d and type '%s' was disapproved with the following " + "policy topic entries:%n", adGroupAd.getAd().getId(), adGroupAd.getAd().getAdType());
            // Display the policy topic entries related to the ad disapproval.
            for (PolicyTopicEntry policyTopicEntry : policySummary.getPolicyTopicEntries()) {
                System.out.printf("  topic id: %s, topic name: '%s'%n", policyTopicEntry.getPolicyTopicId(), policyTopicEntry.getPolicyTopicName());
                // Display the attributes and values that triggered the policy topic.
                if (policyTopicEntry.getPolicyTopicEvidences() != null) {
                    for (PolicyTopicEvidence evidence : policyTopicEntry.getPolicyTopicEvidences()) {
                        System.out.printf("    evidence type: %s%n", evidence.getPolicyTopicEvidenceType());
                        if (evidence.getEvidenceTextList() != null) {
                            for (int i = 0; i < evidence.getEvidenceTextList().length; i++) {
                                System.out.printf("      evidence text[%d]: %s%n", i, evidence.getEvidenceTextList(i));
                            }
                        }
                    }
                }
            }
        }
    } while (serviceQuery.hasNext(page));
    System.out.printf("%d disapproved ads were found.%n", disapprovedAdsCount);
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) PolicyTopicEvidence(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEvidence) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) PolicyTopicEntry(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEntry) AdGroupAdPolicySummary(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Aggregations

AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)2 AdGroupAdPolicySummary (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary)2 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)2 PolicyTopicEntry (com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEntry)2 PolicyTopicEvidence (com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEvidence)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 ServiceQuery (com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1