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

Run() public method

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user, long adGroupId, long keywordId ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
adGroupId long Id of the ad group for which keyword bid /// simulations are retrieved.
keywordId long Id of the keyword for which bid simulations are /// retrieved.
return void
        public void Run(AdWordsUser user, long adGroupId, long keywordId)
        {
            // Get the DataService.
              DataService dataService = (DataService) user.GetService(AdWordsService.v201306.DataService);

              // Create the selector.
              Selector selector = new Selector();
              selector.fields = new string[] {"AdGroupId", "CriterionId", "StartDate", "EndDate", "Bid",
              "LocalClicks", "LocalCost", "MarginalCpc", "LocalImpressions"};

              // Create the filters.
              Predicate adGroupPredicate = new Predicate();
              adGroupPredicate.field = "AdGroupId";
              adGroupPredicate.@operator = PredicateOperator.IN;
              adGroupPredicate.values = new string[] {adGroupId.ToString()};

              Predicate keywordPredicate = new Predicate();
              keywordPredicate.field = "CriterionId";
              keywordPredicate.@operator = PredicateOperator.IN;
              keywordPredicate.values = new string[] {keywordId.ToString()};

              selector.predicates = new Predicate[] {adGroupPredicate, keywordPredicate};

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

              int offset = 0;
              int pageSize = 500;

              CriterionBidLandscapePage page = new CriterionBidLandscapePage();

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

              // Get bid landscape for keywords.
              page = dataService.getCriterionBidLandscape(selector);

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

            foreach (CriterionBidLandscape bidLandscape in page.entries) {
              Console.WriteLine("{0}) Found criterion bid landscape with ad group id '{1}', " +
                  "keyword id '{2}', start date '{3}', end date '{4}', and landscape points:",
                  i, bidLandscape.adGroupId, bidLandscape.criterionId, bidLandscape.startDate,
                  bidLandscape.endDate);
              foreach (BidLandscapeLandscapePoint bidLandscapePoint in
                  bidLandscape.landscapePoints) {
                Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, marginalCpc: {3}, " +
                    "impressions: {4}\n", bidLandscapePoint.bid.microAmount,
                    bidLandscapePoint.clicks, bidLandscapePoint.cost.microAmount,
                    bidLandscapePoint.marginalCpc.microAmount, bidLandscapePoint.impressions);
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of keyword bid landscapes found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to retrieve keyword bid landscapes.", 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)
 {
     GetKeywordBidSimulations codeExample = new GetKeywordBidSimulations();
       Console.WriteLine(codeExample.Description);
       try {
     long adGroupId = long.Parse("INSERT_ADGROUP_ID_HERE");
     long keywordId = long.Parse("INSERT_KEYWORD_ID_HERE");
     codeExample.Run(new AdWordsUser(), adGroupId, keywordId);
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }
GetKeywordBidSimulations