/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the LocationCriterionService. LocationCriterionService locationCriterionService = (LocationCriterionService)user.GetService(AdWordsService.v201607. LocationCriterionService); string[] locationNames = new string[] { "Paris", "Quebec", "Spain", "Deutschland" }; Selector selector = new Selector() { fields = new string[] { Location.Fields.Id, Location.Fields.LocationName, LocationCriterion.Fields.CanonicalName, Location.Fields.DisplayType, Location.Fields.ParentLocations, LocationCriterion.Fields.Reach, Location.Fields.TargetingStatus }, predicates = new Predicate[] { // Location names must match exactly, only EQUALS and IN are supported. Predicate.In(Location.Fields.LocationName, locationNames), // Set the locale of the returned location names. Predicate.Equals(LocationCriterion.Fields.Locale, "en") } }; 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 e) { throw new System.ApplicationException("Failed to get location criteria.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the LocationCriterionService. LocationCriterionService locationCriterionService = (LocationCriterionService) user.GetService(AdWordsService.v201402. 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); } }
public List <GeoTarget> GetLocationNamesByTargetIds(List <string> ids) { Selector selector = new Selector(); selector.fields = new string[] { "Id", "LocationName", "CanonicalName", "DisplayType", "ParentLocations", "Reach" }; // Predicates allow filtering of results Predicate IdPredicate = new Predicate(); IdPredicate.field = "Id"; IdPredicate.@operator = PredicateOperator.EQUALS; IdPredicate.values = ids.ToArray(); selector.predicates = new Predicate[] { IdPredicate }; LocationCriterion[] locationCriteria = _locationCriterionService.get(selector); List <GeoTarget> targets = new List <GeoTarget>(); foreach (string id in ids) { foreach (LocationCriterion target in locationCriteria) { if (target.location.id == Convert.ToInt64(id)) { targets.Add(new GeoTarget() { Id = id, City = target.location.locationName, State = target.location.parentLocations[0].locationName }); } } } return(targets); }