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);
}
}