use of com.google.api.ads.admanager.axis.v202205.LineItemPage in project googleads-java-lib by googleads.
the class UpdateLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the ID of the line item to update.
* @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 LineItemService.
LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
// Create a statement to only select a single line item by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", lineItemId);
// Get the line item.
LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
LineItem lineItem = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Update the line item's priority to High if possible.
if (lineItem.getLineItemType().equals(LineItemType.STANDARD)) {
lineItem.setPriority(6);
// Update the line item on the server.
LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });
for (LineItem updatedLineItem : lineItems) {
System.out.printf("Line item with ID %d and name '%s' was updated.%n", updatedLineItem.getId(), updatedLineItem.getName());
}
} else {
System.out.println("No line items were updated.");
}
}
use of com.google.api.ads.admanager.axis.v202205.LineItemPage in project googleads-java-lib by googleads.
the class GetRecentlyUpdatedLineItems 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 {
LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
// Create a statement to select line items.
StatementBuilder statementBuilder = new StatementBuilder().where("lastModifiedDateTime >= :lastModifiedDateTime").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lastModifiedDateTime", DateTimes.toDateTime(Instant.now().minus(Duration.standardDays(1L)), "America/New_York"));
// Retrieve a small amount of line items at a time, paging through
// until all line items have been retrieved.
int totalResultSetSize = 0;
do {
LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each line item.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (LineItem lineItem : page.getResults()) {
System.out.printf("%d) Line item with ID %d and name '%s' was found.%n", i++, lineItem.getId(), lineItem.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.v202205.LineItemPage in project googleads-java-lib by googleads.
the class PauseLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the ID of the line item to pause.
* @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 LineItemService.
LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
// Create a statement to select a line item.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", lineItemId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get line items by statement.
LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (LineItem lineItem : page.getResults()) {
System.out.printf("%d) Line item with ID %d will be paused.%n", i++, lineItem.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of line items to be paused: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202111.PauseLineItems action = new com.google.api.ads.admanager.axis.v202111.PauseLineItems();
// Perform action.
UpdateResult result = lineItemService.performLineItemAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of line items paused: %d%n", result.getNumChanges());
} else {
System.out.println("No line items were paused.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.LineItemPage in project googleads-java-lib by googleads.
the class GetAllLineItems 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 {
// Get the LineItemService.
LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
// Create a statement to select all line items.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get line items by statement.
LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (LineItem lineItem : page.getResults()) {
System.out.printf("%d) Line item with ID %d and name '%s' was found.%n", i++, lineItem.getId(), lineItem.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.v202205.LineItemPage in project googleads-java-lib by googleads.
the class PauseLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the ID of the line item to pause.
* @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 LineItemService.
LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
// Create a statement to select a line item.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", lineItemId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get line items by statement.
LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (LineItem lineItem : page.getResults()) {
System.out.printf("%d) Line item with ID %d will be paused.%n", i++, lineItem.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of line items to be paused: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202205.PauseLineItems action = new com.google.api.ads.admanager.axis.v202205.PauseLineItems();
// Perform action.
UpdateResult result = lineItemService.performLineItemAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of line items paused: %d%n", result.getNumChanges());
} else {
System.out.println("No line items were paused.");
}
}
}
Aggregations