use of com.google.api.ads.admanager.axis.v202205.Size 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.v202205.Size in project googleads-java-lib by googleads.
the class GetRecentlyModifiedContent 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 recently modified content based on lastModifiedDateTime.
// Changes to content bundle associations will update the lastModifiedDateTime, but
// CMS metadata changes may not change the lastModifiedDateTime.
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"));
// 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.v202205.Size 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());
}
}
use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class CreateCreatives method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param advertiserId the ID of the advertiser (company) that all creatives will be assigned 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.
* @throws IOException if unable to get media data from the URL.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
// Get the CreativeService.
CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
// Create creative size.
Size size = new Size();
size.setWidth(600);
size.setHeight(315);
size.setIsAspectRatio(false);
// Create an image creative.
ImageCreative imageCreative = new ImageCreative();
imageCreative.setName("Image creative #" + new Random().nextInt(Integer.MAX_VALUE));
imageCreative.setAdvertiserId(advertiserId);
imageCreative.setDestinationUrl("http://google.com");
imageCreative.setSize(size);
// Create image asset.
CreativeAsset creativeAsset = new CreativeAsset();
creativeAsset.setFileName("image.jpg");
creativeAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
creativeAsset.setSize(size);
imageCreative.setPrimaryImageAsset(creativeAsset);
// Create an image redirect creative.
ImageRedirectCreative imageRedirectCreative = new ImageRedirectCreative();
imageRedirectCreative.setName("Image redirect creative #" + new Random().nextInt(Integer.MAX_VALUE));
imageRedirectCreative.setAdvertiserId(advertiserId);
imageRedirectCreative.setDestinationUrl("http://google.com");
imageRedirectCreative.setImageUrl("https://goo.gl/3b9Wfh");
imageRedirectCreative.setSize(size);
// Create the creatives on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { imageCreative, imageRedirectCreative });
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());
}
}
use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class CreateCreativesFromTemplates method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param advertiserId the ID of the advertiser (company) that all creatives will be assigned 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.
* @throws IOException if unable to get media data from the URL.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
// Get the CreativeService.
CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
// Create creative size.
Size size = new Size();
size.setWidth(600);
size.setHeight(315);
size.setIsAspectRatio(false);
// Use the image banner with optional third party tracking template.
// To determine what other creative templates exist,
// run GetAllCreativeTemplates.java.
long creativeTemplateId = 10000680L;
// Create a template creative.
TemplateCreative templateCreative = new TemplateCreative();
templateCreative.setName("Template creative #" + new Random().nextInt(Integer.MAX_VALUE));
templateCreative.setAdvertiserId(advertiserId);
templateCreative.setCreativeTemplateId(creativeTemplateId);
templateCreative.setSize(size);
// Create the asset variable value.
AssetCreativeTemplateVariableValue assetVariableValue = new AssetCreativeTemplateVariableValue();
assetVariableValue.setUniqueName("Imagefile");
CreativeAsset asset = new CreativeAsset();
asset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
// Filenames must be unique.
asset.setFileName(String.format("image%s.jpg", new Random().nextInt(Integer.MAX_VALUE)));
assetVariableValue.setAsset(asset);
// Create the image width variable value.
LongCreativeTemplateVariableValue imageWidthVariableValue = new LongCreativeTemplateVariableValue();
imageWidthVariableValue.setUniqueName("Imagewidth");
imageWidthVariableValue.setValue(300L);
// Create the image height variable value.
LongCreativeTemplateVariableValue imageHeightVariableValue = new LongCreativeTemplateVariableValue();
imageHeightVariableValue.setUniqueName("Imageheight");
imageHeightVariableValue.setValue(250L);
// Create the URL variable value.
UrlCreativeTemplateVariableValue urlVariableValue = new UrlCreativeTemplateVariableValue();
urlVariableValue.setUniqueName("ClickthroughURL");
urlVariableValue.setValue("www.google.com");
// Create the target window variable value.
StringCreativeTemplateVariableValue targetWindowVariableValue = new StringCreativeTemplateVariableValue();
targetWindowVariableValue.setUniqueName("Targetwindow");
targetWindowVariableValue.setValue("__blank");
// Set the creative template variables.
templateCreative.setCreativeTemplateVariableValues(new BaseCreativeTemplateVariableValue[] { assetVariableValue, imageWidthVariableValue, imageHeightVariableValue, urlVariableValue, targetWindowVariableValue });
// Create the creative on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { templateCreative });
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