Google.Api.Ads.AdWords.Examples.CSharp.v201306.LookupLocation.Run C# (CSharp) Method

Run() public method

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
return void
        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);
              }
        }

Usage Example

 /// <summary>
 /// Main method, to run this code example as a standalone application.
 /// </summary>
 /// <param name="args">The command line arguments.</param>
 public static void Main(string[] args)
 {
     LookupLocation codeExample = new LookupLocation();
       Console.WriteLine(codeExample.Description);
       try {
     codeExample.Run(new AdWordsUser());
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }