Java API, get fields of AdGroupCriterion

58 views
Skip to first unread message

Daniel Santonja

unread,
May 3, 2016, 9:57:20 AM5/3/16
to AdWords API Forum
Hi all,

I am having some trouble getting the fields of an AdGroupCritrerion object that I have obtain thought a call to AdGroupCriterionService.
In the selector builder I add several fields and if I inspect the object with the debugger there they are indeed but I am unable to get them as they seem to be private attributes and there are no get method to retrieve them.

This is the code
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder
   
.fields(
       
AdGroupCriterionField.Id,
        AdGroupCriterionField.FinalUrls,
        AdGroupCriterionField.Status,
        AdGroupCriterionField.KeywordText)
   
.in(AdGroupCriterionField.CriteriaType, "KEYWORD")
   
.equals(AdGroupCriterionField.Status, "ENABLED")
   
.build();
AdGroupCriterionPage page = keywordService.get(selector);
for(AdGroupCriterion keyword: page.getEntries()){
   
System.out.println(keyword.getCriterion().getId());
    System.out.println(((Keyword) keyword.getCriterion()).getText());
   
System.out.println(keyword.getFinalUrls() //What I expected
}

I am confident that there is a way to retrieve those fields, maybe casting to another class like with the getText() line or through another object but I haven't been able to find the way.

I hope I was clear and thank you.

Anthony Madrigal

unread,
May 3, 2016, 12:39:15 PM5/3/16
to AdWords API Forum
Hi Daniel,

You will need to cast the AdGroupCriterion to the BiddableAdGroupCriterion class. From there, you can get certain fields such as final URLs.

Here is a snippet on how to do so
 BiddableAdGroupCriterion bac =  (BiddableAdGroupCriterion) adGroupCriterionResult;
 
System.out.printf("Keyword final url is %s",bac.getFinalUrls().getUrls(0));

Cheers,
Anthony
AdWords API Team

Daniel Santonja

unread,
May 3, 2016, 1:46:13 PM5/3/16
to AdWords API Forum
Thank you for your help.
Reply all
Reply to author
Forward
0 new messages