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;
}
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();
}
}
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);
}
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());
}
}
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());
}
Aggregations