How to link Keywords and Adgroups ?

31 views
Skip to first unread message

Cumhur YALÇIN

unread,
May 8, 2015, 4:52:06 PM5/8/15
to adwor...@googlegroups.com

Hello people,

I'm just struggling to retrieve Keywords which belongs to an AdGroup inside a campaign.

Here we can see the hierarchy of the objects.

https://support.google.com/adwords/answer/2475865

What I am doing to retrieve is something like this:

      Selector selectorKeyword = new Selector();
      selectorKeyword.fields = new string[] { "Id", "AdGroupId", "KeywordText" };

      // Select only keywords.
      predicate = new Predicate();
      predicate.field = "CriteriaType";
      predicate.@operator = PredicateOperator.EQUALS;
      predicate.values = new string[] { "KEYWORD" };
      Predicate predicateAdGroup = new Predicate();
      predicate.field = "AdGroupId";
      predicate.@operator = PredicateOperator.IN;
      predicate.values = new string[] { adGroup.id.ToString() };
      selectorKeyword.predicates = new Predicate[] { predicate, predicateAdGroup };

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

      AdGroupCriterionPage page = new AdGroupCriterionPage();

      selectorKeyword.paging.startIndex = 0;
      selectorKeyword.paging.numberResults = 500;

      // Get the keywords.
      page = adGroupCriterionService.get(selectorKeyword);


But this throws an exception at the last line of the code which is:

{"[SelectorError.INVALID_PREDICATE_FIELD_NAME @ serviceSelector, RequiredError.REQUIRED @ serviceSelector.predicates[1].operator, RequiredError.REQUIRED @ serviceSelector.predicates[1].field]"}

But we can see in the Google Api documentation that AdGroupId is a filterable selective field of the Selector.

Any ideas, please?


Josh Radcliff (AdWords API Team)

unread,
May 8, 2015, 5:24:55 PM5/8/15
to adwor...@googlegroups.com, in...@doriathtechnology.co.uk
Hi,

It looks like you just have a minor typo in your code. The second Predicate is named predicateAdGroup, but you set the attributes of the first Predicate named predicate in the second section.

      Predicate predicateAdGroup = new Predicate();
      predicate.field = "AdGroupId";
      predicate.@operator = PredicateOperator.IN;
      predicate.values = new string[] { adGroup.id.ToString() };

If you change that section of code to the following, then your example should work as expected.

      Predicate predicateAdGroup = new Predicate();
      predicateAdGroup.field = "AdGroupId";
      predicateAdGroup.@operator = PredicateOperator.IN;
      predicateAdGroup.values = new string[] { adGroup.id.ToString() };

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages