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;
}
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