}
public static void runExample(
AdWordsServices adWordsServices, AdWordsSession session, long adGroupId) throws Exception {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService =
adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create the template ad.
TemplateAd clickToDownloadAppAd = new TemplateAd();
clickToDownloadAppAd.setName("Ad for jupiter adventure game");
clickToDownloadAppAd.setTemplateId(353L);
clickToDownloadAppAd.setUrl(
"http://play.google.com/store/apps/details?id=com.example.jupiteradventure");
clickToDownloadAppAd.setDisplayUrl("play.google.com");
// Create the template elements for the ad. You can refer to
// https://developers.google.com/adwords/api/docs/appendix/templateads
// for the list of available template fields.
TemplateElementField headline = new TemplateElementField();
headline.setName("headline");
headline.setFieldText("Enjoy a Jupiter Adventure");
headline.setType(TemplateElementFieldType.TEXT);
TemplateElementField description1 = new TemplateElementField();
description1.setName("description1");
description1.setFieldText("Realistic physics simulation");
description1.setType(TemplateElementFieldType.TEXT);
TemplateElementField description2 = new TemplateElementField();
description2.setName("description2");
description2.setFieldText("Race against players online");
description2.setType(TemplateElementFieldType.TEXT);
TemplateElementField appId = new TemplateElementField();
appId.setName("appId");
appId.setFieldText("com.example.jupiteradventure");
appId.setType(TemplateElementFieldType.TEXT);
TemplateElementField appStore = new TemplateElementField();
appStore.setName("appStore");
appStore.setFieldText("2");
appStore.setType(TemplateElementFieldType.ENUM);
TemplateElement adData = new TemplateElement();
adData.setUniqueName("adData");
adData.setFields(new TemplateElementField[] {headline, description1, description2, appId,
appStore});
clickToDownloadAppAd.setTemplateElements(new TemplateElement[] {adData});
// Create the AdGroupAd.
AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd();
clickToDownloadAppAdGroupAd.setAdGroupId(adGroupId);
clickToDownloadAppAdGroupAd.setAd(clickToDownloadAppAd);
// Optional: Set the status.
clickToDownloadAppAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(clickToDownloadAppAdGroupAd);
// Create the ads.
AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] {operation});
for (AdGroupAd adGroupAd : result.getValue()) {
System.out.printf("New click-to-download ad with id = \"%d\" and url = \"%s\" " +
"was created.", adGroupAd.getAd().getId(), adGroupAd.getAd().getUrl());
}