Search in sources :

Example 1 with AssetPage

use of com.google.api.ads.adwords.axis.v201809.cm.AssetPage in project googleads-java-lib by googleads.

the class GetAllImageAssets method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the AdGroupAdService.
    AssetServiceInterface assetService = adWordsServices.get(session, AssetServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create the selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AssetField.AssetName, AssetField.AssetStatus, AssetField.ImageFileSize, AssetField.ImageWidth, AssetField.ImageHeight, AssetField.ImageFullSizeUrl).offset(offset).limit(PAGE_SIZE).equals(AssetField.AssetSubtype, AssetType.IMAGE.getValue()).build();
    int totalEntries = 0;
    while (morePages) {
        // Get the image assets.
        AssetPage page = assetService.get(selector);
        // Display the results.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            totalEntries = page.getTotalNumEntries();
            int i = selector.getPaging().getStartIndex();
            for (Asset asset : page.getEntries()) {
                System.out.printf("%d) Image asset with ID %d, name '%s', and status '%s' was found.%n", i, asset.getAssetId(), asset.getAssetName(), asset.getAssetStatus());
            }
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
    System.out.printf("Found %d image assets.%n", totalEntries);
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) Asset(com.google.api.ads.adwords.axis.v201809.cm.Asset) AssetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface) AssetPage(com.google.api.ads.adwords.axis.v201809.cm.AssetPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Aggregations

SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 Asset (com.google.api.ads.adwords.axis.v201809.cm.Asset)1 AssetPage (com.google.api.ads.adwords.axis.v201809.cm.AssetPage)1 AssetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1