use of com.google.api.ads.admanager.axis.v202202.CustomCreative in project googleads-java-lib by googleads.
the class CreateCustomCreatives 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 a custom creative.
CustomCreative customCreative = new CustomCreative();
customCreative.setName("Custom creative #" + new Random().nextInt(Integer.MAX_VALUE));
customCreative.setAdvertiserId(advertiserId);
customCreative.setDestinationUrl("http://google.com");
customCreative.setSize(size);
// Set the custom creative image asset.
CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
customCreativeAsset.setMacroName("IMAGE_ASSET");
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)));
customCreativeAsset.setAsset(asset);
customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] { customCreativeAsset });
// Set the HTML snippet using the custom creative asset macro.
customCreative.setHtmlSnippet("<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" + "<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" + "</a><br>Click above for great deals!");
// Create the creative on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { customCreative });
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.v202202.CustomCreative in project googleads-java-lib by googleads.
the class CreateCustomCreatives 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 a custom creative.
CustomCreative customCreative = new CustomCreative();
customCreative.setName("Custom creative #" + new Random().nextInt(Integer.MAX_VALUE));
customCreative.setAdvertiserId(advertiserId);
customCreative.setDestinationUrl("http://google.com");
customCreative.setSize(size);
// Set the custom creative image asset.
CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
customCreativeAsset.setMacroName("IMAGE_ASSET");
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)));
customCreativeAsset.setAsset(asset);
customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] { customCreativeAsset });
// Set the HTML snippet using the custom creative asset macro.
customCreative.setHtmlSnippet("<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" + "<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" + "</a><br>Click above for great deals!");
// Create the creative on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { customCreative });
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.v202202.CustomCreative in project googleads-java-lib by googleads.
the class CreateCustomCreatives 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 a custom creative.
CustomCreative customCreative = new CustomCreative();
customCreative.setName("Custom creative #" + new Random().nextInt(Integer.MAX_VALUE));
customCreative.setAdvertiserId(advertiserId);
customCreative.setDestinationUrl("http://google.com");
customCreative.setSize(size);
// Set the custom creative image asset.
CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
customCreativeAsset.setMacroName("IMAGE_ASSET");
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)));
customCreativeAsset.setAsset(asset);
customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] { customCreativeAsset });
// Set the HTML snippet using the custom creative asset macro.
customCreative.setHtmlSnippet("<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" + "<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" + "</a><br>Click above for great deals!");
// Create the creative on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { customCreative });
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