use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class UpdateLicas method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the line item ID of the LICA.
* @param creativeId the master or creative set ID of the LICA. For creative sets, set the master
* creative ID.
* @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) throws RemoteException {
// Get the LineItemCreativeAssociationService.
LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
// Create a statement to select a single LICA for a line item.
StatementBuilder statementBuilder = new StatementBuilder().where("lineItemId = :lineItemId AND creativeId = :creativeId").orderBy("lineItemId ASC, creativeId ASC").limit(1).withBindVariableValue("lineItemId", lineItemId).withBindVariableValue("creativeId", creativeId);
// Get the LICA.
LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statementBuilder.toStatement());
LineItemCreativeAssociation lica = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Update the destination URL.
lica.setDestinationUrl("http://news.google.com?newTrackingParameter");
// Update the LICA on the server.
LineItemCreativeAssociation[] licas = licaService.updateLineItemCreativeAssociations(new LineItemCreativeAssociation[] { lica });
for (LineItemCreativeAssociation updatedLica : licas) {
System.out.printf("LICA with line item ID %d and creative ID %d was updated.%n", updatedLica.getLineItemId(), updatedLica.getCreativeId());
}
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class CreatePlacements method getAllAdUnits.
/**
* Gets all ad units.
*/
public static List<AdUnit> getAllAdUnits(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
List<AdUnit> adUnits = new ArrayList<>();
// Get the InventoryService.
InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
// Create a statement to select all ad units.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// 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();
Collections.addAll(adUnits, page.getResults());
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
return adUnits;
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class GetActivePlacements 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 {
PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
// Create a statement to select placements.
StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", InventoryStatus.ACTIVE.toString());
// Retrieve a small amount of placements at a time, paging through
// until all placements have been retrieved.
int totalResultSetSize = 0;
do {
PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each placement.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Placement placement : page.getResults()) {
System.out.printf("%d) Placement with ID %d and name '%s' was found.%n", i++, placement.getId(), placement.getName());
}
}
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.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class ApproveOrders method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param orderId the ID of the order to approve.
* @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 orderId) throws RemoteException {
// Get the OrderService.
OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
// Create a statement to select an order.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", orderId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get orders by statement.
OrderPage page = orderService.getOrdersByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Order order : page.getResults()) {
System.out.printf("%d) Order with ID %d will be approved.%n", i++, order.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of orders to be approved: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202108.ApproveOrders action = new com.google.api.ads.admanager.axis.v202108.ApproveOrders();
// Perform action.
UpdateResult result = orderService.performOrderAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of orders approved: %d%n", result.getNumChanges());
} else {
System.out.println("No orders were approved.");
}
}
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class ArchiveProposalLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param proposalLineItemId the ID of the proposal line item to archive.
* @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 proposalLineItemId) throws RemoteException {
// Get the ProposalLineItemService.
ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
// Create a statement to select a proposal line item.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalLineItemId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get proposal line items by statement.
ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (ProposalLineItem proposalLineItem : page.getResults()) {
System.out.printf("%d) Proposal line item with ID %d will be archived.%n", i++, proposalLineItem.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of proposal line items 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.v202108.ArchiveProposalLineItems action = new com.google.api.ads.admanager.axis.v202108.ArchiveProposalLineItems();
// Perform action.
UpdateResult result = proposalLineItemService.performProposalLineItemAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of proposal line items archived: %d%n", result.getNumChanges());
} else {
System.out.println("No proposal line items were archived.");
}
}
}
Aggregations