Search in sources :

Example 1 with AdGroupPage

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

the class GetAdGroups method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign to use to find ad groups.
 * @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 campaignId) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupField.Id, AdGroupField.Name).orderAscBy(AdGroupField.Name).offset(offset).limit(PAGE_SIZE).equals(AdGroupField.CampaignId, campaignId.toString()).build();
    while (morePages) {
        // Get all ad groups.
        AdGroupPage page = adGroupService.get(selector);
        // Display ad groups.
        if (page.getEntries() != null) {
            for (AdGroup adGroup : page.getEntries()) {
                System.out.printf("Ad group with name '%s' and ID %d was found.%n", adGroup.getName(), adGroup.getId());
            }
        } else {
            System.out.println("No ad groups were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 2 with AdGroupPage

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

the class ProductPartitionTreeImpl method getAdGroupBiddingStrategyConfiguration.

/**
 * Retrieves the {@link BiddingStrategyConfiguration} of an ad group.
 *
 * @param services the AdWordsServices
 * @param session the session to use for the request
 * @param adGroupId the ad group ID
 * @return the non-null BiddingStrategyConfiguration of the ad group
 */
private static BiddingStrategyConfiguration getAdGroupBiddingStrategyConfiguration(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
    Selector selector = new SelectorBuilder().fields(AdGroupField.Id, AdGroupField.BiddingStrategyType, AdGroupField.BiddingStrategyId, AdGroupField.BiddingStrategyName).equalsId(adGroupId).build();
    AdGroupPage adGroupPage = adGroupService.get(selector);
    if (adGroupPage.getEntries() == null || adGroupPage.getEntries().length == 0) {
        throw new IllegalArgumentException("No ad group found with ID " + adGroupId);
    }
    AdGroup adGroup = adGroupPage.getEntries(0);
    Preconditions.checkState(adGroup.getBiddingStrategyConfiguration() != null, "Unexpected state - ad group ID %s has a null BiddingStrategyConfiguration", adGroupId);
    return adGroup.getBiddingStrategyConfiguration();
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Aggregations

SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)2 AdGroupPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage)2 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)2 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)2