/// <summary> /// Gets the shared criteria in a shared set. /// </summary> /// <param name="user">The user that owns the shared set.</param> /// <param name="sharedSetIds">The shared criteria IDs.</param> /// <returns>The list of shared criteria.</returns> private List <SharedCriterion> GetSharedCriteria(AdWordsUser user, List <string> sharedSetIds) { SharedCriterionService sharedCriterionService = (SharedCriterionService)user.GetService(AdWordsService.v201509.SharedCriterionService); Selector selector = new Selector() { fields = new string[] { SharedSet.Fields.SharedSetId, Criterion.Fields.Id, Keyword.Fields.KeywordText, Keyword.Fields.KeywordMatchType, Placement.Fields.PlacementUrl }, predicates = new Predicate[] { Predicate.In(SharedSet.Fields.SharedSetId, sharedSetIds) }, paging = Paging.Default }; List <SharedCriterion> sharedCriteria = new List <SharedCriterion>(); SharedCriterionPage page = new SharedCriterionPage(); try { do { // Get the campaigns. page = sharedCriterionService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = selector.paging.startIndex; foreach (SharedCriterion sharedCriterion in page.entries) { switch (sharedCriterion.criterion.type) { case CriterionType.KEYWORD: Keyword keyword = (Keyword)sharedCriterion.criterion; Console.WriteLine("{0}) Shared negative keyword with ID {1} and text '{2}' " + "was found.", i + 1, keyword.id, keyword.text); break; case CriterionType.PLACEMENT: Placement placement = (Placement)sharedCriterion.criterion; Console.WriteLine("{0}) Shared negative placement with ID {1} and URL '{2}' " + "was found.", i + 1, placement.id, placement.url); break; default: Console.WriteLine("{0}) Shared criteria with ID {1} was found.", i + 1, sharedCriterion.criterion.id); break; } i++; sharedCriteria.Add(sharedCriterion); } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); return(sharedCriteria); } catch (Exception e) { throw new Exception("Failed to get shared criteria.", e); } }
/// <summary> /// Gets the shared criteria in a shared set. /// </summary> /// <param name="user">The user that owns the shared set.</param> /// <param name="sharedSetIds">The shared criteria IDs.</param> /// <returns>The list of shared criteria.</returns> private List <SharedCriterion> GetSharedCriteria(AdWordsUser user, List <string> sharedSetIds) { SharedCriterionService sharedCriterionService = (SharedCriterionService)user.GetService(AdWordsService.v201506.SharedCriterionService); Selector selector = new Selector() { fields = new string[] { "SharedSetId", "Id", "KeywordText", "KeywordMatchType", "PlacementUrl" }, predicates = new Predicate[] { new Predicate() { field = "SharedSetId", @operator = PredicateOperator.IN, values = sharedSetIds.ToArray() } } }; List <SharedCriterion> sharedCriteria = new List <SharedCriterion>(); int offset = 0; int pageSize = 500; SharedCriterionPage page = new SharedCriterionPage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get the campaigns. page = sharedCriterionService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (SharedCriterion sharedCriterion in page.entries) { switch (sharedCriterion.criterion.type) { case CriterionType.KEYWORD: Keyword keyword = (Keyword)sharedCriterion.criterion; Console.WriteLine("Shared negative keyword with ID {0} and text '{1}' was " + "found.", keyword.id, keyword.text); break; case CriterionType.PLACEMENT: Placement placement = (Placement)sharedCriterion.criterion; Console.WriteLine("Shared negative placement with ID {0} and URL '{1}' " + "was found.", placement.id, placement.url); break; default: Console.WriteLine("Shared criteria with ID {0} was found.", sharedCriterion.criterion.id); break; } sharedCriteria.Add(sharedCriterion); } } offset += pageSize; } while (offset < page.totalNumEntries); return(sharedCriteria); } catch (Exception e) { throw new Exception("Failed to get shared criteria.", e); } }