Google.Api.Ads.AdWords.Examples.CSharp.v201306.GetPlacementIdeas.Run C# (CSharp) Méthode

Run() public méthode

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
Résultat void
        public void Run(AdWordsUser user)
        {
            // Get the TargetingIdeaService.
              TargetingIdeaService targetingIdeaService =
              (TargetingIdeaService) user.GetService(AdWordsService.v201306.TargetingIdeaService);

              // Create seed url.
              string url = "mars.google.com";

              // Create the selector.
              TargetingIdeaSelector selector = new TargetingIdeaSelector();
              selector.requestType = RequestType.IDEAS;
              selector.ideaType = IdeaType.PLACEMENT;
              selector.requestedAttributeTypes = new AttributeType[] {AttributeType.CRITERION,
              AttributeType.PLACEMENT_TYPE};

              // Create related to url search parameter.
              RelatedToUrlSearchParameter relatedToUrlSearchParameter = new RelatedToUrlSearchParameter();
              relatedToUrlSearchParameter.urls = new string[] {url};
              relatedToUrlSearchParameter.includeSubUrls = false;
              selector.searchParameters = new SearchParameter[] {relatedToUrlSearchParameter};

              // Set selector paging.
              selector.paging = new Paging();

              int offset = 0;
              int pageSize = 500;

              TargetingIdeaPage page = new TargetingIdeaPage();

              try {
            do {
              selector.paging.startIndex = offset;
              selector.paging.numberResults = pageSize;

              // Get placement ideas.
              page = targetingIdeaService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;

            foreach (TargetingIdea idea in page.entries) {
              foreach (Type_AttributeMapEntry entry in idea.data) {
                if (entry.key == AttributeType.CRITERION) {
                  CriterionAttribute placementAttribute = entry.value as CriterionAttribute;
                  Placement placement = (Placement) placementAttribute.value;
                  Console.WriteLine("Related placement urls were found at '{0}'.",
                      (placementAttribute.value as Placement).url);
                }
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of related placements found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to retrieve related placements.", 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)
 {
     GetPlacementIdeas codeExample = new GetPlacementIdeas();
       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));
       }
 }
GetPlacementIdeas