0
votes

I'm just struggling with Google AdWords api to retrieve Keywords which belongs to a 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:

          // Create a selector.
      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?

1

1 Answers

0
votes

I found the problem.

What I intended to use for AdgroupId predicate object was

predicateAdGroup

but unfortunately I used

predicate

named object instead of that. That's why the second predicate expression was null.

Glad that i have realized this quite early :)

Thanks.