use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class AddCompleteCampaignsUsingBatchJob method buildAdGroupAdOperations.
private static List<AdGroupAdOperation> buildAdGroupAdOperations(List<AdGroupOperation> adGroupOperations) {
List<AdGroupAdOperation> operations = new ArrayList<>();
for (AdGroupOperation adGroupOperation : adGroupOperations) {
long adGroupId = adGroupOperation.getOperand().getId();
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
ExpandedTextAd textAd = new ExpandedTextAd();
textAd.setHeadlinePart1("Luxury Cruise to Mars");
textAd.setHeadlinePart2("Visit the Red Planet in style.");
textAd.setDescription("Low-gravity fun for everyone!");
textAd.setFinalUrls(new String[] { "http://www.example.com/1" });
adGroupAd.setAd(textAd);
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(adGroupAd);
operations.add(operation);
}
return operations;
}
use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class AddExpandedTextAds method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group where the ad will be created.
* @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);
List<AdGroupAdOperation> operations = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_ADS; i++) {
// Create expanded text ad.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setHeadlinePart1(String.format("Cruise #%d to Mars", i));
expandedTextAd.setHeadlinePart2("Best Space Cruise Line");
expandedTextAd.setHeadlinePart3("For Your Loved Ones");
expandedTextAd.setDescription("Buy your tickets now!");
expandedTextAd.setDescription2("Discount ends soon");
expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/" + i });
// Create ad group ad.
AdGroupAd expandedTextAdGroupAd = new AdGroupAd();
expandedTextAdGroupAd.setAdGroupId(adGroupId);
expandedTextAdGroupAd.setAd(expandedTextAd);
// Optional: set the status.
expandedTextAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(expandedTextAdGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
operations.add(adGroupAdOperation);
}
// Add ads.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations.toArray(new AdGroupAdOperation[operations.size()]));
// Display ads.
Arrays.stream(result.getValue()).map(adGroupAdResult -> (ExpandedTextAd) adGroupAdResult.getAd()).forEach(newAd -> System.out.printf("Expanded text ad with ID %d and headline '%s | %s%s' was added.%n", newAd.getId(), newAd.getHeadlinePart1(), newAd.getHeadlinePart2(), newAd.getHeadlinePart3() == null ? "" : String.format(" | %s", newAd.getHeadlinePart3())));
}
use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class GetExpandedTextAds method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group to use to find expanded text 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;
boolean morePages = true;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.Status, AdGroupAdField.HeadlinePart1, AdGroupAdField.HeadlinePart2, AdGroupAdField.Description).orderAscBy(AdGroupAdField.Id).offset(offset).limit(PAGE_SIZE).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).in(AdGroupAdField.Status, "ENABLED", "PAUSED").equals("AdType", "EXPANDED_TEXT_AD").build();
while (morePages) {
// Get all ads.
AdGroupAdPage page = adGroupAdService.get(selector);
// Display ads.
if (page.getEntries() != null && page.getEntries().length > 0) {
for (AdGroupAd adGroupAd : page.getEntries()) {
ExpandedTextAd expandedTextAd = (ExpandedTextAd) adGroupAd.getAd();
System.out.printf("Expanded text ad with ID %d, status '%s', and headline '%s - %s' was found.%n", adGroupAd.getAd().getId(), adGroupAd.getStatus(), expandedTextAd.getHeadlinePart1(), expandedTextAd.getHeadlinePart2());
}
} else {
System.out.println("No expanded text ads were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
morePages = offset < page.getTotalNumEntries();
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class UpdateExpandedTextAd method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adId the ID of the ad to update.
* @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 adId) throws RemoteException {
// Get the AdService.
AdServiceInterface adService = adWordsServices.get(session, AdServiceInterface.class);
// Creates an expanded text ad using the provided ad ID.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setId(adId);
// Updates some properties of the expanded text ad.
expandedTextAd.setHeadlinePart1("Cruise to Pluto #" + System.currentTimeMillis());
expandedTextAd.setHeadlinePart2("Tickets on sale now");
expandedTextAd.setDescription("Best space cruise ever.");
expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/" });
expandedTextAd.setFinalMobileUrls(new String[] { "http://www.example.com/mobile" });
// Creates ad group ad operation and adds it to the list.
AdOperation operation = new AdOperation();
operation.setOperator(Operator.SET);
operation.setOperand(expandedTextAd);
// Updates the ad on the server.
ExpandedTextAd updatedAd = (ExpandedTextAd) adService.mutate(new AdOperation[] { operation }).getValue(0);
// Prints out some information.
System.out.printf("Expanded text ad with ID %d was updated.%n", updatedAd.getId());
System.out.printf("Headline part 1 is '%s'.%nHeadline part 2 is '%s'.%nDescription is '%s'.%n", updatedAd.getHeadlinePart1(), updatedAd.getHeadlinePart2(), updatedAd.getDescription());
System.out.printf("Final URL is '%s'.%nFinal mobile URL is '%s'.%n", updatedAd.getFinalUrls()[0], updatedAd.getFinalMobileUrls()[0]);
}
use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class AddAdCustomizer method createAdsWithCustomizations.
/**
* Creates expanded text ads that use ad customizations for the specified ad group IDs.
*/
private static void createAdsWithCustomizations(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, String feedName) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
ExpandedTextAd textAd = new ExpandedTextAd();
textAd.setHeadlinePart1(String.format("Luxury Cruise to {=%s.Name}", feedName));
textAd.setHeadlinePart2(String.format("Only {=%s.Price}", feedName));
textAd.setDescription(String.format("Offer ends in {=countdown(%s.Date)}!", feedName));
textAd.setFinalUrls(new String[] { "http://www.example.com" });
// We add the same ad to both ad groups. When they serve, they will show different values, since
// they match different feed items.
List<AdGroupAdOperation> adGroupAdOperations = new ArrayList<>();
for (Long adGroupId : adGroupIds) {
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(textAd);
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(adGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
adGroupAdOperations.add(adGroupAdOperation);
}
AdGroupAdReturnValue adGroupAdReturnValue = adGroupAdService.mutate(adGroupAdOperations.toArray(new AdGroupAdOperation[adGroupAdOperations.size()]));
for (AdGroupAd addedAd : adGroupAdReturnValue.getValue()) {
System.out.printf("Created an ad with ID %d, type '%s' and status '%s'.%n", addedAd.getAd().getId(), addedAd.getAd().getAdType(), addedAd.getStatus());
}
}
Aggregations