Search in sources :

Example 41 with Creative

use of com.google.api.ads.admanager.axis.v202108.Creative in project googleads-java-lib by googleads.

the class CreateCreativeSets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param masterCreativeId the ID of the master creative in the creative set.
 * @param companionCreativeId the ID of the companion creative in the creative set.
 * @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 masterCreativeId, long companionCreativeId) throws RemoteException {
    // Get the CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    CreativeSet creativeSet = new CreativeSet();
    creativeSet.setName("Creative set #" + new Random().nextInt(Integer.MAX_VALUE));
    creativeSet.setMasterCreativeId(masterCreativeId);
    creativeSet.setCompanionCreativeIds(new long[] { companionCreativeId });
    // Create the creative set on the server.
    CreativeSet createdCreativeSet = creativeSetService.createCreativeSet(creativeSet);
    System.out.printf("A creative set with ID %d, master creative ID %d, " + "and companion creative IDs [%s] was created.%n", createdCreativeSet.getId(), createdCreativeSet.getMasterCreativeId(), Longs.join(",", createdCreativeSet.getCompanionCreativeIds()));
}
Also used : Random(java.util.Random) CreativeSet(com.google.api.ads.admanager.axis.v202108.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeSetServiceInterface)

Example 42 with Creative

use of com.google.api.ads.admanager.axis.v202108.Creative 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());
    }
}
Also used : CreativeAsset(com.google.api.ads.admanager.axis.v202111.CreativeAsset) AspectRatioImageCreative(com.google.api.ads.admanager.axis.v202111.AspectRatioImageCreative) Creative(com.google.api.ads.admanager.axis.v202111.Creative) ImageCreative(com.google.api.ads.admanager.axis.v202111.ImageCreative) Size(com.google.api.ads.admanager.axis.v202111.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) AspectRatioImageCreative(com.google.api.ads.admanager.axis.v202111.AspectRatioImageCreative) ImageCreative(com.google.api.ads.admanager.axis.v202111.ImageCreative) AspectRatioImageCreative(com.google.api.ads.admanager.axis.v202111.AspectRatioImageCreative)

Example 43 with Creative

use of com.google.api.ads.admanager.axis.v202108.Creative 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)

Example 44 with Creative

use of com.google.api.ads.admanager.axis.v202108.Creative in project googleads-java-lib by googleads.

the class GetImageCreatives 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 {
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create a statement to select creatives.
    StatementBuilder statementBuilder = new StatementBuilder().where("creativeType = :creativeType").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("creativeType", "ImageCreative");
    // Retrieve a small amount of creatives at a time, paging through
    // until all creatives have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Creative creative : page.getResults()) {
                System.out.printf("%d) Creative with ID %d and name '%s' was found.%n", i++, creative.getId(), creative.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : Creative(com.google.api.ads.admanager.axis.v202111.Creative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202111.CreativePage)

Example 45 with Creative

use of com.google.api.ads.admanager.axis.v202108.Creative 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());
    }
}
Also used : CustomCreativeAsset(com.google.api.ads.admanager.axis.v202111.CustomCreativeAsset) CustomCreative(com.google.api.ads.admanager.axis.v202111.CustomCreative) Random(java.util.Random) CustomCreativeAsset(com.google.api.ads.admanager.axis.v202111.CustomCreativeAsset) CreativeAsset(com.google.api.ads.admanager.axis.v202111.CreativeAsset) CustomCreative(com.google.api.ads.admanager.axis.v202111.CustomCreative) 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)

Aggregations

Random (java.util.Random)19 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)18 Size (com.google.api.ads.admanager.axis.v202108.Size)11 Creative (com.google.api.ads.admanager.axis.v202202.Creative)9 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface)9 Creative (com.google.api.ads.admanager.axis.v202108.Creative)8 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)8 Creative (com.google.api.ads.admanager.axis.v202111.Creative)8 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface)8 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationServiceInterface)6 Size (com.google.api.ads.admanager.axis.v202202.Size)6 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)5 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)5 CreativePlaceholder (com.google.api.ads.admanager.axis.v202108.CreativePlaceholder)5 CreativeWrapper (com.google.api.ads.admanager.axis.v202108.CreativeWrapper)5 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeWrapperServiceInterface)5 Goal (com.google.api.ads.admanager.axis.v202108.Goal)5 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)5 LineItemCreativeAssociation (com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociation)5 Targeting (com.google.api.ads.admanager.axis.v202108.Targeting)5