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()));
}
Aggregations