Search in sources :

Example 11 with CreativeSet

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

the class CreateCreativeSets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param masterCreativeId the ID of the master creative in the creative set.
 * @param companionCreativeId the ID of the companion creative in the creative set.
 * @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 masterCreativeId, long companionCreativeId) throws RemoteException {
    // Get the CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    CreativeSet creativeSet = new CreativeSet();
    creativeSet.setName("Creative set #" + new Random().nextInt(Integer.MAX_VALUE));
    creativeSet.setMasterCreativeId(masterCreativeId);
    creativeSet.setCompanionCreativeIds(new long[] { companionCreativeId });
    // Create the creative set on the server.
    CreativeSet createdCreativeSet = creativeSetService.createCreativeSet(creativeSet);
    System.out.printf("A creative set with ID %d, master creative ID %d, " + "and companion creative IDs [%s] was created.%n", createdCreativeSet.getId(), createdCreativeSet.getMasterCreativeId(), Longs.join(",", createdCreativeSet.getCompanionCreativeIds()));
}
Also used : Random(java.util.Random) CreativeSet(com.google.api.ads.admanager.axis.v202111.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeSetServiceInterface)

Example 12 with CreativeSet

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

the class GetCreativeSetsForMasterCreative method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param masterCreativeId the ID of the master creative.
 * @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 masterCreativeId) throws RemoteException {
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to select creative sets.
    StatementBuilder statementBuilder = new StatementBuilder().where("masterCreativeId = :masterCreativeId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("masterCreativeId", masterCreativeId);
    // Retrieve a small amount of creative sets at a time, paging through
    // until all creative sets have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative set.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeSet creativeSet : page.getResults()) {
                System.out.printf("%d) Creative set with ID %d and name '%s' was found.%n", i++, creativeSet.getId(), creativeSet.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CreativeSetPage(com.google.api.ads.admanager.axis.v202111.CreativeSetPage) CreativeSet(com.google.api.ads.admanager.axis.v202111.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeSetServiceInterface)

Aggregations

CreativeSet (com.google.api.ads.admanager.axis.v202108.CreativeSet)4 CreativeSetServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeSetServiceInterface)4 CreativeSet (com.google.api.ads.admanager.axis.v202111.CreativeSet)4 CreativeSetServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeSetServiceInterface)4 CreativeSet (com.google.api.ads.admanager.axis.v202202.CreativeSet)4 CreativeSetServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeSetServiceInterface)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)3 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)3 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)3 CreativeSetPage (com.google.api.ads.admanager.axis.v202108.CreativeSetPage)3 CreativeSetPage (com.google.api.ads.admanager.axis.v202111.CreativeSetPage)3 CreativeSetPage (com.google.api.ads.admanager.axis.v202202.CreativeSetPage)3 Random (java.util.Random)3