use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class CreateNativeCreatives 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);
// Use the system defined native app install creative template.
long nativeAppInstallTemplateId = 10004400L;
// Use 1x1 as the size for native creatives.
Size size = new Size();
size.setWidth(1);
size.setHeight(1);
size.setIsAspectRatio(false);
// Create a native app install creative for the Pie Noon app.
TemplateCreative nativeAppInstallCreative = new TemplateCreative();
nativeAppInstallCreative.setName("Native creative #" + new Random().nextInt(Integer.MAX_VALUE));
nativeAppInstallCreative.setAdvertiserId(advertiserId);
nativeAppInstallCreative.setDestinationUrl("https://play.google.com/store/apps/details?id=com.google.fpl.pie_noon");
nativeAppInstallCreative.setCreativeTemplateId(nativeAppInstallTemplateId);
nativeAppInstallCreative.setSize(size);
List<BaseCreativeTemplateVariableValue> templateVariables = new ArrayList<>();
// Set the headline.
StringCreativeTemplateVariableValue headlineVariableValue = new StringCreativeTemplateVariableValue();
headlineVariableValue.setUniqueName("Headline");
headlineVariableValue.setValue("Pie Noon");
templateVariables.add(headlineVariableValue);
// Set the body text.
StringCreativeTemplateVariableValue bodyVariableValue = new StringCreativeTemplateVariableValue();
bodyVariableValue.setUniqueName("Body");
bodyVariableValue.setValue("Try multi-screen mode!");
templateVariables.add(bodyVariableValue);
// Set the image asset.
AssetCreativeTemplateVariableValue imageVariableValue = new AssetCreativeTemplateVariableValue();
imageVariableValue.setUniqueName("Image");
CreativeAsset imageAsset = new CreativeAsset();
imageAsset.setFileName("image" + new Random().nextInt(Integer.MAX_VALUE) + ".png");
imageAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://lh4.ggpht.com/" + "GIGNKdGHMEHFDw6TM2bgAUDKPQQRIReKZPqEpMeEhZOPYnTdOQGaSpGSEZflIFs0iw=h300"));
imageVariableValue.setAsset(imageAsset);
templateVariables.add(imageVariableValue);
// Set the price.
StringCreativeTemplateVariableValue priceVariableValue = new StringCreativeTemplateVariableValue();
priceVariableValue.setUniqueName("Price");
priceVariableValue.setValue("Free");
templateVariables.add(priceVariableValue);
// Set app icon image asset.
AssetCreativeTemplateVariableValue appIconVariableValue = new AssetCreativeTemplateVariableValue();
appIconVariableValue.setUniqueName("Appicon");
CreativeAsset appIconAsset = new CreativeAsset();
appIconAsset.setFileName("icon" + new Random().nextInt(Integer.MAX_VALUE) + ".png");
appIconAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://lh6.ggpht.com/" + "Jzvjne5CLs6fJ1MHF-XeuUfpABzl0YNMlp4RpHnvPRCIj4--eTDwtyouwUDzVVekXw=w300"));
appIconVariableValue.setAsset(appIconAsset);
templateVariables.add(appIconVariableValue);
// Set the call to action text.
StringCreativeTemplateVariableValue callToActionVariableValue = new StringCreativeTemplateVariableValue();
callToActionVariableValue.setUniqueName("Calltoaction");
callToActionVariableValue.setValue("Install");
templateVariables.add(callToActionVariableValue);
// Set the star rating.
StringCreativeTemplateVariableValue starRatingVariableValue = new StringCreativeTemplateVariableValue();
starRatingVariableValue.setUniqueName("Starrating");
starRatingVariableValue.setValue("4");
templateVariables.add(starRatingVariableValue);
// Set the store type.
StringCreativeTemplateVariableValue storeVariableValue = new StringCreativeTemplateVariableValue();
storeVariableValue.setUniqueName("Store");
storeVariableValue.setValue("Google Play");
templateVariables.add(storeVariableValue);
// Set the deep link URL.
UrlCreativeTemplateVariableValue deepLinkVariableValue = new UrlCreativeTemplateVariableValue();
deepLinkVariableValue.setUniqueName("DeeplinkclickactionURL");
deepLinkVariableValue.setValue("market://details?id=com.google.fpl.pie_noon");
templateVariables.add(deepLinkVariableValue);
nativeAppInstallCreative.setCreativeTemplateVariableValues(templateVariables.toArray(new BaseCreativeTemplateVariableValue[templateVariables.size()]));
// Create the creative on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { nativeAppInstallCreative });
for (Creative createdCreative : creatives) {
System.out.printf("A native creative with ID %d and name '%s' was" + " created and can be previewed at: %s%n", createdCreative.getId(), createdCreative.getName(), createdCreative.getPreviewUrl());
}
}
use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class CreateVideoCreatives 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(640);
size.setHeight(360);
size.setIsAspectRatio(false);
// Create an image creative.
VideoCreative videoCreative = new VideoCreative();
videoCreative.setName("Video creative #" + new Random().nextInt(Integer.MAX_VALUE));
videoCreative.setAdvertiserId(advertiserId);
videoCreative.setDestinationUrl("https://google.com");
videoCreative.setSize(size);
videoCreative.setVideoSourceUrl("https://storage.googleapis.com/interactive-media-ads/media/android.mp4");
videoCreative.setDuration(115000);
// Create the creatives on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { videoCreative });
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(), ((VideoCreative) createdCreative).getVastPreviewUrl());
}
}
use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class GetAllCreativeWrappers 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 CreativeWrapperService.
CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
// Create a statement to select all creative wrappers.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// 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 was found.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
}
}
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 DeactivateCustomFields method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param customFieldId the ID of the custom field 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 customFieldId) throws RemoteException {
// Get the CustomFieldService.
CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
// Create a statement to select a custom field.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customFieldId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom fields by statement.
CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CustomField customField : page.getResults()) {
System.out.printf("%d) Custom field with ID %d will be deactivated.%n", i++, customField.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of custom fields 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.DeactivateCustomFields action = new com.google.api.ads.admanager.axis.v202205.DeactivateCustomFields();
// Perform action.
UpdateResult result = customFieldService.performCustomFieldAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of custom fields deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No custom fields were deactivated.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.Size in project googleads-java-lib by googleads.
the class GetAllCustomFields 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 CustomFieldService.
CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
// Create a statement to get all custom fields.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom fields by statement.
CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CustomField customField : page.getResults()) {
System.out.printf("%d) Custom field with ID %d and name '%s' was found.%n", i++, customField.getId(), customField.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Aggregations