Search in sources :

Example 6 with AssetCreativeTemplateVariableValue

use of com.google.api.ads.admanager.axis.v202111.AssetCreativeTemplateVariableValue 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());
    }
}
Also used : TemplateCreative(com.google.api.ads.admanager.axis.v202111.TemplateCreative) LongCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.LongCreativeTemplateVariableValue) Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202111.CreativeAsset) TemplateCreative(com.google.api.ads.admanager.axis.v202111.TemplateCreative) Creative(com.google.api.ads.admanager.axis.v202111.Creative) Size(com.google.api.ads.admanager.axis.v202111.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface) StringCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.StringCreativeTemplateVariableValue) AssetCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.AssetCreativeTemplateVariableValue) UrlCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.UrlCreativeTemplateVariableValue)

Aggregations

Random (java.util.Random)6 ArrayList (java.util.ArrayList)3 AssetCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202108.AssetCreativeTemplateVariableValue)2 Creative (com.google.api.ads.admanager.axis.v202108.Creative)2 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)2 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)2 Size (com.google.api.ads.admanager.axis.v202108.Size)2 StringCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202108.StringCreativeTemplateVariableValue)2 TemplateCreative (com.google.api.ads.admanager.axis.v202108.TemplateCreative)2 UrlCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202108.UrlCreativeTemplateVariableValue)2 AssetCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202111.AssetCreativeTemplateVariableValue)2 Creative (com.google.api.ads.admanager.axis.v202111.Creative)2 CreativeAsset (com.google.api.ads.admanager.axis.v202111.CreativeAsset)2 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface)2 Size (com.google.api.ads.admanager.axis.v202111.Size)2 StringCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202111.StringCreativeTemplateVariableValue)2 TemplateCreative (com.google.api.ads.admanager.axis.v202111.TemplateCreative)2 UrlCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202111.UrlCreativeTemplateVariableValue)2 AssetCreativeTemplateVariableValue (com.google.api.ads.admanager.axis.v202202.AssetCreativeTemplateVariableValue)2 Creative (com.google.api.ads.admanager.axis.v202202.Creative)2