use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class AddExpandedTextAdWithUpgradedUrls 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);
// Create expanded text ad with a tracking template and custom parameters.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setHeadlinePart1("Luxury Cruise to Mars");
expandedTextAd.setHeadlinePart2("Visit the Red Planet in style.");
expandedTextAd.setDescription("Low-gravity fun for everyone!");
// Specify a tracking url for 3rd party tracking provider. You may
// specify one at customer, campaign, ad group, ad, criterion or
// feed item levels.
expandedTextAd.setTrackingUrlTemplate("http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}");
// Since your tracking url has two custom parameters, provide their
// values too. This can be provided at campaign, ad group, ad, criterion
// or feed item levels.
CustomParameter seasonParameter = new CustomParameter();
seasonParameter.setKey("season");
seasonParameter.setValue("christmas");
CustomParameter promoCodeParameter = new CustomParameter();
promoCodeParameter.setKey("promocode");
promoCodeParameter.setValue("NYC123");
CustomParameters trackingUrlParameters = new CustomParameters();
trackingUrlParameters.setParameters(new CustomParameter[] { seasonParameter, promoCodeParameter });
expandedTextAd.setUrlCustomParameters(trackingUrlParameters);
// Specify a list of final urls. This field cannot be set if url field is
// set. This may be specified at ad, criterion, and feed item levels.
expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/cruise/space/", "http://www.example.com/locations/mars/" });
// Specify a list of final mobile urls. This field cannot be set if url field is
// set or finalUrls is not set. This may be specified at ad, criterion, and feed
// item levels.
expandedTextAd.setFinalMobileUrls(new String[] { "http://mobile.example.com/cruise/space/", "http://mobile.example.com/locations/mars/" });
// Create ad group ad.
AdGroupAd textAdGroupAd = new AdGroupAd();
textAdGroupAd.setAdGroupId(adGroupId);
textAdGroupAd.setAd(expandedTextAd);
// Optional: Set status.
textAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create operation.
AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
textAdGroupAdOperation.setOperand(textAdGroupAd);
textAdGroupAdOperation.setOperator(Operator.ADD);
AdGroupAdOperation[] operations = new AdGroupAdOperation[] { textAdGroupAdOperation };
// Add ad.
AdGroupAd adGroupAdResult = adGroupAdService.mutate(operations).getValue(0);
// Display ad.
System.out.printf("Ad with ID %d and tracking URL template '%s' was added.", adGroupAdResult.getAd().getId(), adGroupAdResult.getAd().getTrackingUrlTemplate());
}
use of com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd in project googleads-java-lib by googleads.
the class ValidateTextAd method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group for the ad.
* @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 {
// Enable validation.
session.setValidateOnly(true);
// Get the validation AdGroupAdService.
AdGroupAdServiceInterface adGroupAdValidationService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create text ad.
ExpandedTextAd textAd1 = new ExpandedTextAd();
textAd1.setHeadlinePart1("Luxury Cruise to Mars");
textAd1.setHeadlinePart2("Visit the Red Planet in style.");
textAd1.setDescription("Low-gravity fun for everyone!");
textAd1.setFinalUrls(new String[] { "http://www.example.com" });
// Create ad group ad.
AdGroupAd textAdGroupAd1 = new AdGroupAd();
textAdGroupAd1.setAdGroupId(adGroupId);
textAdGroupAd1.setAd(textAd1);
// Create operations.
AdGroupAdOperation textAdGroupAdOperation1 = new AdGroupAdOperation();
textAdGroupAdOperation1.setOperand(textAdGroupAd1);
textAdGroupAdOperation1.setOperator(Operator.ADD);
AdGroupAdOperation[] operations = new AdGroupAdOperation[] { textAdGroupAdOperation1 };
// Add ads.
adGroupAdValidationService.mutate(operations);
// No error means the request is valid.
// Now let's check an invalid ad using a very long line to trigger an error.
textAd1.setDescription("Low-gravity fun for all astronauts in orbit.");
try {
adGroupAdValidationService.mutate(operations);
} catch (ApiException e) {
System.err.printf("Validation failed for the following reason: %s%n", e.getMessage());
}
}
Aggregations