Search in sources :

Example 1 with SuggestedAdUnitUpdateResult

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

the class ApproveSuggestedAdUnits method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param numRequests the number of requests for suggested ad units greater than which to approve.
 * @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, long numRequests) throws RemoteException {
    // Get the SuggestedAdUnitService.
    SuggestedAdUnitServiceInterface suggestedAdUnitService = adManagerServices.get(session, SuggestedAdUnitServiceInterface.class);
    // Create a statement to only select suggested ad units that are highly
    // requested.
    StatementBuilder statementBuilder = new StatementBuilder().where("numRequests >= :numRequests").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("numRequests", numRequests);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get suggested ad units by statement.
        SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (SuggestedAdUnit suggestedAdUnit : page.getResults()) {
                System.out.printf("%d) Suggested ad unit with ID '%s' will be approved.%n", i++, suggestedAdUnit.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of suggested ad units to be approved: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.ApproveSuggestedAdUnits action = new com.google.api.ads.admanager.axis.v202202.ApproveSuggestedAdUnits();
        // Perform action.
        SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of new ad units created: %d%n", result.getNewAdUnitIds().length);
        } else {
            System.out.println("No suggested ad units were approved.");
        }
    }
}
Also used : SuggestedAdUnitUpdateResult(com.google.api.ads.admanager.axis.v202202.SuggestedAdUnitUpdateResult) SuggestedAdUnitServiceInterface(com.google.api.ads.admanager.axis.v202202.SuggestedAdUnitServiceInterface) SuggestedAdUnit(com.google.api.ads.admanager.axis.v202202.SuggestedAdUnit) SuggestedAdUnitPage(com.google.api.ads.admanager.axis.v202202.SuggestedAdUnitPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)

Example 2 with SuggestedAdUnitUpdateResult

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

the class ApproveSuggestedAdUnits method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param numRequests the number of requests for suggested ad units greater than which to approve.
 * @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, long numRequests) throws RemoteException {
    // Get the SuggestedAdUnitService.
    SuggestedAdUnitServiceInterface suggestedAdUnitService = adManagerServices.get(session, SuggestedAdUnitServiceInterface.class);
    // Create a statement to only select suggested ad units that are highly
    // requested.
    StatementBuilder statementBuilder = new StatementBuilder().where("numRequests >= :numRequests").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("numRequests", numRequests);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get suggested ad units by statement.
        SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (SuggestedAdUnit suggestedAdUnit : page.getResults()) {
                System.out.printf("%d) Suggested ad unit with ID '%s' will be approved.%n", i++, suggestedAdUnit.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of suggested ad units to be approved: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202108.ApproveSuggestedAdUnits action = new com.google.api.ads.admanager.axis.v202108.ApproveSuggestedAdUnits();
        // Perform action.
        SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of new ad units created: %d%n", result.getNewAdUnitIds().length);
        } else {
            System.out.println("No suggested ad units were approved.");
        }
    }
}
Also used : SuggestedAdUnitUpdateResult(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitUpdateResult) SuggestedAdUnitServiceInterface(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitServiceInterface) SuggestedAdUnit(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnit) SuggestedAdUnitPage(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)

Example 3 with SuggestedAdUnitUpdateResult

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

the class ApproveSuggestedAdUnits method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param numRequests the number of requests for suggested ad units greater than which to approve.
 * @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, long numRequests) throws RemoteException {
    // Get the SuggestedAdUnitService.
    SuggestedAdUnitServiceInterface suggestedAdUnitService = adManagerServices.get(session, SuggestedAdUnitServiceInterface.class);
    // Create a statement to only select suggested ad units that are highly
    // requested.
    StatementBuilder statementBuilder = new StatementBuilder().where("numRequests >= :numRequests").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("numRequests", numRequests);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get suggested ad units by statement.
        SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (SuggestedAdUnit suggestedAdUnit : page.getResults()) {
                System.out.printf("%d) Suggested ad unit with ID '%s' will be approved.%n", i++, suggestedAdUnit.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of suggested ad units to be approved: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202111.ApproveSuggestedAdUnits action = new com.google.api.ads.admanager.axis.v202111.ApproveSuggestedAdUnits();
        // Perform action.
        SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of new ad units created: %d%n", result.getNewAdUnitIds().length);
        } else {
            System.out.println("No suggested ad units were approved.");
        }
    }
}
Also used : SuggestedAdUnitUpdateResult(com.google.api.ads.admanager.axis.v202111.SuggestedAdUnitUpdateResult) SuggestedAdUnitServiceInterface(com.google.api.ads.admanager.axis.v202111.SuggestedAdUnitServiceInterface) SuggestedAdUnit(com.google.api.ads.admanager.axis.v202111.SuggestedAdUnit) SuggestedAdUnitPage(com.google.api.ads.admanager.axis.v202111.SuggestedAdUnitPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)1 SuggestedAdUnit (com.google.api.ads.admanager.axis.v202108.SuggestedAdUnit)1 SuggestedAdUnitPage (com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitPage)1 SuggestedAdUnitServiceInterface (com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitServiceInterface)1 SuggestedAdUnitUpdateResult (com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitUpdateResult)1 SuggestedAdUnit (com.google.api.ads.admanager.axis.v202111.SuggestedAdUnit)1 SuggestedAdUnitPage (com.google.api.ads.admanager.axis.v202111.SuggestedAdUnitPage)1 SuggestedAdUnitServiceInterface (com.google.api.ads.admanager.axis.v202111.SuggestedAdUnitServiceInterface)1 SuggestedAdUnitUpdateResult (com.google.api.ads.admanager.axis.v202111.SuggestedAdUnitUpdateResult)1 SuggestedAdUnit (com.google.api.ads.admanager.axis.v202202.SuggestedAdUnit)1 SuggestedAdUnitPage (com.google.api.ads.admanager.axis.v202202.SuggestedAdUnitPage)1 SuggestedAdUnitServiceInterface (com.google.api.ads.admanager.axis.v202202.SuggestedAdUnitServiceInterface)1 SuggestedAdUnitUpdateResult (com.google.api.ads.admanager.axis.v202202.SuggestedAdUnitUpdateResult)1