use of com.google.api.ads.admanager.axis.v202205.Label in project googleads-java-lib by googleads.
the class DeactivateCreativeWrappersForLabel method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param labelId the ID of the creative wrapper label to deactivate.
* @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 labelId) throws RemoteException {
// Get the CreativeWrapperService.
CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
// Create a statement to select the active creative wrappers for the
// given label.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE status = :status AND labelId = :labelId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString()).withBindVariableValue("labelId", labelId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get creative wrappers by statement.
CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CreativeWrapper creativeWrapper : page.getResults()) {
System.out.printf("%d) Creative wrapper with ID %d applying to label ID" + " %d will be deactivated.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of creative wrappers to be deactivated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
DeactivateCreativeWrappers action = new DeactivateCreativeWrappers();
// Perform action.
UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of creative wrappers deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No creative wrappers were deactivated.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.Label in project googleads-java-lib by googleads.
the class GetActiveCreativeWrappers method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @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) throws RemoteException {
CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
// Create a statement to select creative wrappers.
StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString());
// Retrieve a small amount of creative wrappers at a time, paging through
// until all creative wrappers have been retrieved.
int totalResultSetSize = 0;
do {
CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each creative wrapper.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CreativeWrapper creativeWrapper : page.getResults()) {
System.out.printf("%d) Creative wrapper with ID %d and label ID %d was found.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.v202205.Label in project googleads-java-lib by googleads.
the class CreateCreativeWrappers method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param labelId the ID of the label that can be associated with creative wrappers.
* @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 labelId) throws RemoteException {
// Get the CreativeWrapperService.
CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
// Create a creative wrapper.
CreativeWrapper innerCreativeWrapper = new CreativeWrapper();
// A label can only be associated with one creative wrapper.
innerCreativeWrapper.setLabelId(labelId);
innerCreativeWrapper.setOrdering(CreativeWrapperOrdering.INNER);
innerCreativeWrapper.setHtmlHeader("<b>My creative wrapper header</b>");
innerCreativeWrapper.setHtmlFooter("<b>My creative wrapper footer</b>");
// Create the creative wrapper on the server.
CreativeWrapper[] creativeWrappers = creativeWrapperService.createCreativeWrappers(new CreativeWrapper[] { innerCreativeWrapper });
for (CreativeWrapper createdCreativeWrapper : creativeWrappers) {
System.out.printf("Creative wrapper with ID %d applying to label ID %d was created.%n", createdCreativeWrapper.getId(), createdCreativeWrapper.getLabelId());
}
}
use of com.google.api.ads.admanager.axis.v202205.Label in project googleads-java-lib by googleads.
the class DeactivateLabels method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param labelId the ID of the label to deactivate.
* @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 labelId) throws RemoteException {
// Get the LabelService.
LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
// Create a statement to select a label.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", labelId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get labels by statement.
LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Label label : page.getResults()) {
System.out.printf("%d) Label with ID %d will be deactivated.%n", i++, label.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of labels to be deactivated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202202.DeactivateLabels action = new com.google.api.ads.admanager.axis.v202202.DeactivateLabels();
// Perform action.
UpdateResult result = labelService.performLabelAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of labels deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No labels were deactivated.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.Label in project googleads-java-lib by googleads.
the class GetActiveLabels method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @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) throws RemoteException {
LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
// Create a statement to select labels.
StatementBuilder statementBuilder = new StatementBuilder().where("isActive = :isActive").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("isActive", true);
// Retrieve a small amount of labels at a time, paging through
// until all labels have been retrieved.
int totalResultSetSize = 0;
do {
LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each label.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Label label : page.getResults()) {
System.out.printf("%d) Label with ID %d and name '%s' was found.%n", i++, label.getId(), label.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Aggregations