Search in sources :

Example 31 with InventoryServiceInterface

use of com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface in project googleads-java-lib by googleads.

the class GetAllAdUnitSizes method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Create a statement to select all ad unit sizes.
    StatementBuilder statementBuilder = new StatementBuilder();
    // Get all ad unit sizes.
    AdUnitSize[] adUnitSizes = inventoryService.getAdUnitSizesByStatement(statementBuilder.toStatement());
    if (adUnitSizes != null) {
        for (int i = 0; i < adUnitSizes.length; i++) {
            AdUnitSize adUnitSize = adUnitSizes[i];
            System.out.printf("%d) Ad unit size of dimensions '%s' was found.%n", i, adUnitSize.getFullDisplayString());
        }
    } else {
        System.out.println("No ad unit sizes found.");
    }
}
Also used : AdUnitSize(com.google.api.ads.admanager.axis.v202202.AdUnitSize) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)

Example 32 with InventoryServiceInterface

use of com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface in project googleads-java-lib by googleads.

the class GetAllAdUnits method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Create a statement to select all ad units.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (AdUnit adUnit : page.getResults()) {
                System.out.printf("%d) Ad unit with ID '%s' and name '%s' was found.%n", i++, adUnit.getId(), adUnit.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : AdUnitPage(com.google.api.ads.admanager.axis.v202202.AdUnitPage) AdUnit(com.google.api.ads.admanager.axis.v202202.AdUnit) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)

Example 33 with InventoryServiceInterface

use of com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface in project googleads-java-lib by googleads.

the class GetTopLevelAdUnits method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Set the parent ad unit's ID for all children ad units to be fetched from.
    String parentAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create a statement to select ad units under the parent ad unit.
    StatementBuilder statementBuilder = new StatementBuilder().where("parentId = :parentId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("parentId", parentAdUnitId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (AdUnit adUnit : page.getResults()) {
                System.out.printf("%d) Ad unit with ID '%s' and name '%s' was found.%n", i++, adUnit.getId(), adUnit.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) AdUnitPage(com.google.api.ads.admanager.axis.v202202.AdUnitPage) AdUnit(com.google.api.ads.admanager.axis.v202202.AdUnit) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)

Example 34 with InventoryServiceInterface

use of com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface in project googleads-java-lib by googleads.

the class GetAdUnitHierarchy method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the effective root ad unit.
    String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create a statement to select only the root ad unit by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", rootAdUnitId);
    AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
    AdUnit effectiveRootAdUnit = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Get all ad units.
    List<AdUnit> adUnits = getAllAdUnits(adManagerServices, session);
    buildAndDisplayAdUnitTree(effectiveRootAdUnit, adUnits);
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface) AdUnitPage(com.google.api.ads.admanager.axis.v202205.AdUnitPage) AdUnit(com.google.api.ads.admanager.axis.v202205.AdUnit) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)

Example 35 with InventoryServiceInterface

use of com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface in project googleads-java-lib by googleads.

the class GetAllAdUnitSizes method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Create a statement to select all ad unit sizes.
    StatementBuilder statementBuilder = new StatementBuilder();
    // Get all ad unit sizes.
    AdUnitSize[] adUnitSizes = inventoryService.getAdUnitSizesByStatement(statementBuilder.toStatement());
    if (adUnitSizes != null) {
        for (int i = 0; i < adUnitSizes.length; i++) {
            AdUnitSize adUnitSize = adUnitSizes[i];
            System.out.printf("%d) Ad unit size of dimensions '%s' was found.%n", i, adUnitSize.getFullDisplayString());
        }
    } else {
        System.out.println("No ad unit sizes found.");
    }
}
Also used : AdUnitSize(com.google.api.ads.admanager.axis.v202205.AdUnitSize) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)

Aggregations

ArrayList (java.util.ArrayList)12 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface)9 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)9 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface)9 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface)9 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)8 AdUnit (com.google.api.ads.admanager.axis.v202108.AdUnit)8 AdUnit (com.google.api.ads.admanager.axis.v202111.AdUnit)8 AdUnit (com.google.api.ads.admanager.axis.v202202.AdUnit)8 AdUnit (com.google.api.ads.admanager.axis.v202205.AdUnit)8 AdUnitPage (com.google.api.ads.admanager.axis.v202108.AdUnitPage)7 AdUnitPage (com.google.api.ads.admanager.axis.v202111.AdUnitPage)7 AdUnitPage (com.google.api.ads.admanager.axis.v202202.AdUnitPage)7 AdUnitPage (com.google.api.ads.admanager.axis.v202205.AdUnitPage)7 Random (java.util.Random)4 AdUnitSize (com.google.api.ads.admanager.axis.v202108.AdUnitSize)3 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface)3