Retrieving all AdFields using Selector throws exceptio?

8 views
Skip to first unread message

Suresh Kumar Shenbagam

unread,
Jul 25, 2019, 2:05:44 PM7/25/19
to AdWords API and Google Ads API Forum
Hi,

I was trying to retrieve all Ad fields for Ads inside an AdGroup. If my AdGroup has multiple ads, say for example 5 ads each one is of different type like Expanded Text Ad, MultiAssetAd etc.,

Now, I collect all the AdIds inside an AdGroup and pass it to the selector, I am getting INVALID_FIELD_NAME exception.

Sample code:

public static List<Ad> loadAds(
     
AdWordsServicesInterface adWordsServices, AdWordsSession session, Collection<String> adIds) {


   
AdServiceInterface adService = adWordsServices.get(session, AdServiceInterface.class);


   
List<Ad> ads = new ArrayList<>();


   
int offset = 0;


   
// Create selector.
   
SelectorBuilder builder =
       
new SelectorBuilder()
           
.fields(AdField.values())
           
.in(AdField.Id, adIds.toArray(new String[0]))
           
.offset(offset)
           
.limit(PAGE_SIZE_LIMIT);


   
AdPage page = new AdPage();
   
do {
     
// Get campaigns.
     
// page = withRetryPolicy(() -> adService.get(builder.build()));


     
try {page = adService.get(builder.build());} catch (RemoteException e){// TODO Auto-generated catch block
  e
.printStackTrace();}
     
if (page.getEntries() != null) {
        ads
.addAll(Arrays.asList(page.getEntries()));
     
}


      offset
+= PAGE_SIZE_LIMIT;
      builder
.increaseOffsetBy(PAGE_SIZE_LIMIT);
   
} while (offset < page.getTotalNumEntries());


   
return ads;
 
}

How can I retrieve all the AdFields?

Suresh

Google Ads API Forum Advisor Prod

unread,
Jul 26, 2019, 3:24:05 AM7/26/19
to adwor...@googlegroups.com
Hi Suresh,

Thank you for posting your concern.

If you wish to retrieve the specific fields using the AdService, you may refer to this link.

Talking about the selector that you've used, I can see that you are using the AdService.get operation to retrieve the data of your ads. But for your convenience, we have readily available Java sample code that you can use to retrieve the data of your ads. In this example, the AdGroupAdService.get() is used. You may try and implement something similar to that example using your preferred service, which is the AdService.

If the error persists, let me know and you can provide the complete SOAP requests and response logs via Reply privately to author option together with customer ID.

Regards,
Ejay
Google Ads API Team



ref:_00D1U1174p._5001UEGQlL:ref
Reply all
Reply to author
Forward
0 new messages