public void Run(AdWordsUser user, long adGroupId)
{
// Get the AdGroupAdService.
AdGroupAdService adGroupAdService =
(AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService);
// Create the template ad.
TemplateAd clickToDownloadAppAd = new TemplateAd();
clickToDownloadAppAd.name = "Ad for demo game";
clickToDownloadAppAd.templateId = 353;
clickToDownloadAppAd.url =
"http://play.google.com/store/apps/details?id=com.example.demogame";
clickToDownloadAppAd.displayUrl = "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 avaliable template fields.
TemplateElementField headline = new TemplateElementField();
headline.name = "headline";
headline.fieldText = "Enjoy your drive in Mars";
headline.type = TemplateElementFieldType.TEXT;
TemplateElementField description1 = new TemplateElementField();
description1.name = "description1";
description1.fieldText = "Realistic physics simulation";
description1.type = TemplateElementFieldType.TEXT;
TemplateElementField description2 = new TemplateElementField();
description2.name = "description2";
description2.fieldText = "Race against players online";
description2.type = TemplateElementFieldType.TEXT;
TemplateElementField appId = new TemplateElementField();
appId.name = "appId";
appId.fieldText = "com.example.demogame";
appId.type = TemplateElementFieldType.TEXT;
TemplateElementField appStore = new TemplateElementField();
appStore.name = "appStore";
appStore.fieldText = "2";
appStore.type = TemplateElementFieldType.ENUM;
TemplateElement adData = new TemplateElement();
adData.uniqueName = "adData";
adData.fields = new TemplateElementField[] {headline, description1, description2, appId,
appStore};
clickToDownloadAppAd.templateElements = new TemplateElement[] {adData};
// Create the adgroupad.
AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd();
clickToDownloadAppAdGroupAd.adGroupId = adGroupId;
clickToDownloadAppAdGroupAd.ad = clickToDownloadAppAd;
// Optional: Set the status.
clickToDownloadAppAdGroupAd.status = AdGroupAdStatus.PAUSED;
// Create the operation.
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.@operator = Operator.ADD;
operation.operand = clickToDownloadAppAdGroupAd;
try {
// Create the ads.
AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[] {operation});
// Display the results.
if (retval != null && retval.value != null) {
foreach (AdGroupAd adGroupAd in retval.value) {
Console.WriteLine("New click-to-download ad with id = \"{0}\" and url = \"{1}\" " +
"was created.", adGroupAd.ad.id, adGroupAd.ad.url);
}
} else {
Console.WriteLine("No click-to-download ads were created.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to create click-to-download ad.", ex);
}
}