use of com.google.api.ads.admanager.axis.v202202.CreativeSetServiceInterface 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()));
}
use of com.google.api.ads.admanager.axis.v202202.CreativeSetServiceInterface 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);
}
Aggregations