public void Run(AdWordsUser user)
{
// Get the LocationCriterionService.
LocationCriterionService locationCriterionService =
(LocationCriterionService) user.GetService(AdWordsService.v201306.
LocationCriterionService);
string[] locationNames = new string[] {"Paris", "Quebec", "Spain", "Deutschland"};
Selector selector = new Selector();
selector.fields = new string[] {"Id", "LocationName", "CanonicalName", "DisplayType",
"ParentLocations", "Reach", "TargetingStatus"};
// Location names must match exactly, only EQUALS and IN are supported.
Predicate predicate1 = new Predicate();
predicate1.field = "LocationName";
predicate1.@operator = PredicateOperator.IN;
predicate1.values = locationNames;
// Set the locale of the returned location names.
Predicate predicate2 = new Predicate();
predicate2.field = "Locale";
predicate2.@operator = PredicateOperator.EQUALS;
predicate2.values = new string[] {"en"};
selector.predicates = new Predicate[] {predicate1, predicate2};
try {
// Make the get request.
LocationCriterion[] locationCriteria = locationCriterionService.get(selector);
// Display the resulting location criteria.
foreach (LocationCriterion locationCriterion in locationCriteria) {
string parentLocations = "";
if (locationCriterion.location != null &&
locationCriterion.location.parentLocations != null) {
foreach (Location location in locationCriterion.location.parentLocations) {
parentLocations += GetLocationString(location) + ", ";
}
parentLocations.TrimEnd(',', ' ');
} else {
parentLocations = "N/A";
}
Console.WriteLine("The search term '{0}' returned the location '{1}' of type '{2}' " +
"with parent locations '{3}', reach '{4}' and targeting status '{5}.",
locationCriterion.searchTerm, locationCriterion.location.locationName,
locationCriterion.location.displayType, parentLocations, locationCriterion.reach,
locationCriterion.location.targetingStatus);
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to get location criteria.", ex);
}
}