Search in sources :

Example 16 with CreativeSetServiceInterface

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

the class UpdateCreativeSets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeSetId the ID of the creative set to update.
 * @param companionCreativeId the ID of the companion creative to add to 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 creativeSetId, long companionCreativeId) throws RemoteException {
    // Get the CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to only select a single creative set by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeSetId);
    // Get the creative set.
    CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
    CreativeSet creativeSet = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Add the companion creative to the creative set.
    creativeSet.setCompanionCreativeIds(Longs.concat(creativeSet.getCompanionCreativeIds(), new long[] { companionCreativeId }));
    // Update the creative set on the server.
    CreativeSet updatedCreativeSet = creativeSetService.updateCreativeSet(creativeSet);
    System.out.printf("A creative set with ID %d, master creative ID %d, " + "and companion creative IDs [%s] was updated.", updatedCreativeSet.getId(), updatedCreativeSet.getMasterCreativeId(), Longs.join(",", updatedCreativeSet.getCompanionCreativeIds()));
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) CreativeSetPage(com.google.api.ads.admanager.axis.v202205.CreativeSetPage) CreativeSet(com.google.api.ads.admanager.axis.v202205.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202205.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 CreativeSet (com.google.api.ads.admanager.axis.v202205.CreativeSet)4 CreativeSetServiceInterface (com.google.api.ads.admanager.axis.v202205.CreativeSetServiceInterface)4 Random (java.util.Random)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 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.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 CreativeSetPage (com.google.api.ads.admanager.axis.v202205.CreativeSetPage)3