How to get labels attached to Google Adwords Ads

115 views
Skip to first unread message

Paul Grenyer

unread,
Jul 26, 2016, 3:38:54 PM7/26/16
to AdWords API Forum
I want to be able to get the labels attached to a google adwords ad via the Java api.

I can get the ads:

final AdGroupAdPage page = service.get(selector.build());


if (page.getEntries() == null)
   
return;


for (AdGroupAd ad : page.getEntries())
   ads
.add((TextAd)ad.getAd());



But there's no method to get label(s) from an Ad.

I can list all the labels:

Selector selector = new SelectorBuilder()
       
.fields(LabelField.LabelName)
       
.fields(LabelField.LabelId)
       
.fields(LabelField.LabelStatus)
       
.build();


       
LabelPage page = labelService.get(selector);
       
if (page.getEntries() != null) {
           
for (Label label : page.getEntries()) {
                 
System.out.println("Label id " + label.getId() + ", label name " + label.getName() + ", label status " + label.getStatus());
           
}
       
}


But I can't get the Ad ids they belong too.


Anthony Madrigal

unread,
Jul 26, 2016, 4:34:17 PM7/26/16
to AdWords API Forum
Hi Paul,

You can get the labels of an ad by using the AdGroupAdService. You can use this example as a basis.

You can add the following line to get the first label of an ad
adGroupAd.getLabels(0).getName();

Cheers,
Anthony
AdWords API Team
Reply all
Reply to author
Forward
0 new messages