Search in sources :

Example 1 with AdGroup

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

the class AddDynamicSearchAdsCampaign method createAdGroup.

/**
 * Creates the ad group.
 */
private static AdGroup createAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, Campaign campaign) throws ApiException, RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create the ad group.
    AdGroup adGroup = new AdGroup();
    // Required: Set the ad group's type to Dynamic Search Ads.
    adGroup.setAdGroupType(AdGroupType.SEARCH_DYNAMIC_ADS);
    adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
    adGroup.setCampaignId(campaign.getId());
    adGroup.setStatus(AdGroupStatus.PAUSED);
    // Recommended: Set a tracking URL template for your ad group if you want to use URL
    // tracking software.
    adGroup.setTrackingUrlTemplate("http://tracker.example.com/traveltracker/{escapedlpurl}");
    // Set the ad group bids.
    BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
    CpcBid cpcBid = new CpcBid();
    cpcBid.setBid(new Money());
    cpcBid.getBid().setMicroAmount(3000000L);
    biddingConfig.setBids(new Bids[] { cpcBid });
    adGroup.setBiddingStrategyConfiguration(biddingConfig);
    // Create the operation.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.ADD);
    AdGroup newAdGroup = adGroupService.mutate(new AdGroupOperation[] { operation }).getValue(0);
    System.out.printf("Ad group with name '%s' and ID %d was added.%n", newAdGroup.getName(), newAdGroup.getId());
    return newAdGroup;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 2 with AdGroup

use of com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup 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 3 with AdGroup

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

the class AddShoppingDynamicRemarketingCampaign method createAdGroup.

/**
 * Creates an ad group in the specified campaign.
 *
 * @param campaign the campaign to which the ad group should be attached.
 * @return the ad group that was created.
 */
private static AdGroup createAdGroup(AdWordsServicesInterface services, AdWordsSession session, Campaign campaign) throws RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
    AdGroup group = new AdGroup();
    group.setName("Dynamic remarketing ad group");
    group.setCampaignId(campaign.getId());
    group.setStatus(AdGroupStatus.ENABLED);
    AdGroupOperation op = new AdGroupOperation();
    op.setOperand(group);
    op.setOperator(Operator.ADD);
    AdGroupReturnValue result = adGroupService.mutate(new AdGroupOperation[] { op });
    return result.getValue(0);
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 4 with AdGroup

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

the class RemoveAdGroup method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to remove.
 * @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 AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create ad group with REMOVED status.
    AdGroup adGroup = new AdGroup();
    adGroup.setId(adGroupId);
    adGroup.setStatus(AdGroupStatus.REMOVED);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.SET);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation };
    // Remove ad group.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        System.out.printf("Ad group with name '%s' and ID %d was removed.%n", adGroupResult.getName(), adGroupResult.getId());
    }
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 5 with AdGroup

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

the class AxisSerializerTest method testSerialize.

@Test
public void testSerialize() throws SAXException, IOException {
    BatchJobMutateRequest mutate = new BatchJobMutateRequest();
    List<Operation> ops = Lists.newArrayList();
    Campaign campaign = new Campaign();
    campaign.setId(-1L);
    campaign.setName("Test campaign");
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    ops.add(new CampaignOperation(Operator.ADD, "ADD", campaign));
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Test ad group");
    adGroup.setCampaignId(campaign.getId());
    ops.add(new AdGroupOperation(Operator.ADD, "ADD", adGroup));
    mutate.setOperations(ops.toArray(new Operation[0]));
    AxisSerializer serializer = new AxisSerializer();
    StringWriter writer = new StringWriter();
    SerializationContext context = new SerializationContext(writer);
    context.setSendDecl(true);
    context.setPretty(true);
    serializer.serialize(mutate, context);
    String serializedRequest = writer.toString();
    assertNotNull("Serialized request is null", serializedRequest);
    String expectedSerializedRequest = CharStreams.toString(new InputStreamReader(AxisSerializerTest.class.getResourceAsStream("resources/BatchJobMutate.request.xml"), UTF_8));
    Diff diff = DiffBuilder.compare(expectedSerializedRequest).withTest(serializedRequest).checkForSimilar().build();
    assertFalse("Serialized request does not match expected XML", diff.hasDifferences());
}
Also used : SerializationContext(org.apache.axis.encoding.SerializationContext) BatchJobMutateRequest(com.google.api.ads.adwords.axis.utils.v201809.batchjob.BatchJobMutateRequest) InputStreamReader(java.io.InputStreamReader) Diff(org.xmlunit.diff.Diff) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Operation(com.google.api.ads.adwords.axis.v201809.cm.Operation) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) StringWriter(java.io.StringWriter) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation) Test(org.junit.Test)

Aggregations

AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)14 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)9 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)9 AdGroupReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue)6 Test (org.junit.Test)6 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)5 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)5 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)4 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)4 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)3 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)3 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage)2 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)2 CriterionError (com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError)2 InputStreamReader (java.io.InputStreamReader)2 Source (javax.xml.transform.Source)2