use of com.google.api.ads.admanager.axis.v202205.UpdateResult 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.v202111.DeactivateLabels action = new com.google.api.ads.admanager.axis.v202111.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.UpdateResult in project googleads-java-lib by googleads.
the class DeactivateLicas method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the ID of the line item to deactivate LICAs for.
* @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 lineItemId) throws RemoteException {
// Get the LineItemCreativeAssociationService.
LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
// Create a statement to select all LICAs for a line item.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE lineItemId = :lineItemId").orderBy("lineItemId ASC, creativeId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lineItemId", lineItemId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get LICAs by statement.
LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (LineItemCreativeAssociation lica : page.getResults()) {
if (lica.getCreativeSetId() != null) {
System.out.printf("%d) LICA with line item ID %d and creative " + "set ID %d will be deactivated.%n", i++, lica.getLineItemId(), lica.getCreativeSetId());
} else {
System.out.printf("%d) LICA with line item ID %d and creative ID %d will be deactivated.%n", i++, lica.getLineItemId(), lica.getCreativeId());
}
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of LICAs to be deactivated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations();
// Perform action.
UpdateResult result = licaService.performLineItemCreativeAssociationAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of LICAs deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No LICAs were deactivated.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.UpdateResult in project googleads-java-lib by googleads.
the class PushCreativeToDevices method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the ID of the line item to push to a device.
* @param creativeId the ID of the creative
* to push to a device.
* @param linkedDeviceId the ID of the linked device to push the LICA to.
* @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 lineItemId, long creativeId, long linkedDeviceId) throws RemoteException {
// Get the LineItemCreativeAssociationService.
LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
// Create a statement to select a single linked device.
// Linked devices can be read from the linked_device PQL table.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :linkedDeviceId").withBindVariableValue("linkedDeviceId", linkedDeviceId);
CreativePushOptions options = new CreativePushOptions();
options.setLineItemId(lineItemId);
options.setCreativeId(creativeId);
UpdateResult updateResult = licaService.pushCreativeToDevices(statementBuilder.toStatement(), options);
System.out.printf("Pushed creative to %d devices%n", updateResult.getNumChanges());
}
use of com.google.api.ads.admanager.axis.v202205.UpdateResult in project googleads-java-lib by googleads.
the class ArchiveAdUnits method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param parentAdUnitId the ad unit ID to archive underneath.
* @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, String parentAdUnitId) throws RemoteException {
// Get the InventoryService.
InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
// Create a statement to select ad units under the parent ad unit and the
// parent ad unit.
StatementBuilder statementBuilder = new StatementBuilder().where("parentId = :parentId or id = :parentId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("parentId", parentAdUnitId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get ad units by statement.
AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (AdUnit adUnit : page.getResults()) {
System.out.printf("%d) Ad unit with ID '%s' and name '%s' will be archived.%n", i++, adUnit.getId(), adUnit.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of ad units to be archived: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202205.ArchiveAdUnits action = new com.google.api.ads.admanager.axis.v202205.ArchiveAdUnits();
// Perform action.
UpdateResult result = inventoryService.performAdUnitAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of ad units archived: %d%n", result.getNumChanges());
} else {
System.out.println("No ad units were archived.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.UpdateResult 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.v202205.DeactivateLabels action = new com.google.api.ads.admanager.axis.v202205.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.");
}
}
}
Aggregations