use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class GetTopLevelAdUnits 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 InventoryService.
InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
// Get the NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Set the parent ad unit's ID for all children ad units to be fetched from.
String parentAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
// Create a statement to select ad units under the parent ad unit.
StatementBuilder statementBuilder = new StatementBuilder().where("parentId = :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' was found.%n", i++, adUnit.getId(), adUnit.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.Size in project googleads-java-lib by googleads.
the class UpdateAdUnits method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param adUnitId the ID of the ad unit 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, String adUnitId) throws RemoteException {
// Get the InventoryService.
InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
// Create a statement to only select a single ad unit by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", adUnitId);
// Get the ad unit.
AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
AdUnit adUnit = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
List<AdUnitSize> adUnitSizes = new ArrayList<>(Arrays.asList(adUnit.getAdUnitSizes()));
// Create a 480x60 web ad unit size.
Size size = new Size();
size.setWidth(468);
size.setHeight(60);
AdUnitSize adUnitSize = new AdUnitSize();
adUnitSize.setSize(size);
adUnitSize.setEnvironmentType(EnvironmentType.BROWSER);
adUnitSizes.add(adUnitSize);
// Update the ad unit sizes.
adUnit.setAdUnitSizes(adUnitSizes.toArray(new AdUnitSize[] {}));
// Update the ad unit on the server.
AdUnit[] adUnits = inventoryService.updateAdUnits(new AdUnit[] { adUnit });
for (AdUnit updatedAdUnit : adUnits) {
List<String> adUnitSizeStrings = new ArrayList<>();
for (AdUnitSize updatedAdUnitSize : updatedAdUnit.getAdUnitSizes()) {
adUnitSizeStrings.add(String.format("%dx%d", updatedAdUnitSize.getSize().getWidth(), updatedAdUnitSize.getSize().getHeight()));
}
System.out.printf("Ad unit with ID '%s', name '%s', and sizes [%s] was updated.%n", updatedAdUnit.getId(), updatedAdUnit.getName(), Joiner.on(", ").join(adUnitSizeStrings));
}
}
use of com.google.api.ads.admanager.axis.v202205.Size 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.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.Size 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.Size in project googleads-java-lib by googleads.
the class GetAllCmsMetadataValues 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 CmsMetadataService.
CmsMetadataServiceInterface cmsMetadataService = adManagerServices.get(session, CmsMetadataServiceInterface.class);
// Create a statement to select all CMS metadata values.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get CMS metadata values by statement.
CmsMetadataValuePage page = cmsMetadataService.getCmsMetadataValuesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CmsMetadataValue cmsMetadataValue : page.getResults()) {
System.out.printf("%d) CMS metadata value with ID %d and name '%s' associated with the " + "CmsMetadataKey with ID %d and name '%s' was found.%n", i++, cmsMetadataValue.getCmsMetadataValueId(), cmsMetadataValue.getValueName(), cmsMetadataValue.getKey().getId(), cmsMetadataValue.getKey().getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Aggregations