use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class UpdateLabels method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param labelId the ID of the label 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 labelId) throws RemoteException {
// Get the LabelService.
LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
// Create a statement to only select a single label by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", labelId);
// Get the label.
LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
Label label = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Update the label description.
label.setDescription("New label description");
// Update the label on the server.
Label[] labels = labelService.updateLabels(new Label[] { label });
for (Label updatedLabel : labels) {
System.out.printf("Label with ID %d and name '%s' was updated.%n", updatedLabel.getId(), updatedLabel.getName());
}
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class GetLineItemsThatNeedCreatives 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("isMissingCreatives = :isMissingCreatives").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("isMissingCreatives", true);
// 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.utils.v202205.StatementBuilder 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.v202108.PauseLineItems action = new com.google.api.ads.admanager.axis.v202108.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.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class GetAllContent 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 ContentService.
ContentServiceInterface contentService = adManagerServices.get(session, ContentServiceInterface.class);
// Create a statement to get all content.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get content by statement.
ContentPage page = contentService.getContentByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Content content : page.getResults()) {
String contentBundleIds = content.getContentBundleIds() == null ? "[]" : Arrays.toString(content.getContentBundleIds());
System.out.printf("%d) Content with ID %d and name '%s' belonging to bundle IDs %s was found.%n", i++, content.getId(), content.getName(), contentBundleIds);
}
}
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 CopyImageCreatives method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param creativeId the ID of the image creative to copy.
* @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 creativeId) throws RemoteException {
// Get the CreativeService.
CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
// Create a statement to get the image creative.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", creativeId);
// Get the creative.
ImageCreative imageCreative = (ImageCreative) creativeService.getCreativesByStatement(statementBuilder.toStatement()).getResults()[0];
// Fetch the image asset.
CreativeAsset assetToCopy = imageCreative.getPrimaryImageAsset();
Size aspectRatioSize = imageCreative.getSize();
aspectRatioSize.setIsAspectRatio(true);
AspectRatioImageCreative newImageCreative = new AspectRatioImageCreative();
newImageCreative.setName("Copy of original image creative");
newImageCreative.setSize(aspectRatioSize);
newImageCreative.setAdvertiserId(imageCreative.getAdvertiserId());
newImageCreative.setImageAssets(new CreativeAsset[] { assetToCopy });
newImageCreative.setDestinationUrl(imageCreative.getDestinationUrl());
// Create the creative on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { newImageCreative });
for (Creative createdCreative : creatives) {
System.out.printf("A creative with ID %d, name '%s', and type '%s'" + " was created and can be previewed at: %s%n", createdCreative.getId(), createdCreative.getName(), createdCreative.getClass().getSimpleName(), createdCreative.getPreviewUrl());
}
}
Aggregations