public void Run(AdWordsUser user, long adGroupId)
{
// Get the AdGroupAdService.
AdGroupAdService adGroupAdService =
(AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService);
// Set the validateOnly headers.
adGroupAdService.RequestHeader.validateOnly = true;
// Create your text ad.
TextAd textAd = new TextAd();
textAd.headline = "Luxury Cruise to Mars";
textAd.description1 = "Visit the Red Planet in style.";
textAd.description2 = "Low-gravity fun for everyone!!";
textAd.displayUrl = "www.example.com";
textAd.url = "http://www.example.com";
AdGroupAd textAdGroupAd = new AdGroupAd();
textAdGroupAd.adGroupId = adGroupId;
textAdGroupAd.ad = textAd;
AdGroupAdOperation textAdOperation = new AdGroupAdOperation();
textAdOperation.@operator = Operator.ADD;
textAdOperation.operand = textAdGroupAd;
try {
AdGroupAdReturnValue retVal = adGroupAdService.mutate(
(new AdGroupAdOperation[] {textAdOperation}));
// Since validation is ON, result will be null.
Console.WriteLine("text ad validated successfully.");
} catch (AdWordsApiException ex) {
// This block will be hit if there is a validation error from the server.
Console.WriteLine("There were validation error(s) while adding text ad.");
if (ex.ApiException != null) {
foreach (ApiError error in ((ApiException) ex.ApiException).errors) {
Console.WriteLine(" Error type is '{0}' and fieldPath is '{1}'.",
error.ApiErrorType, error.fieldPath);
}
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to validate text ad.", ex);
}
}