Search in sources :

Example 1 with AspectRatioImageCreative

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

Example 2 with AspectRatioImageCreative

use of com.google.api.ads.admanager.axis.v202202.AspectRatioImageCreative 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.v202202.CreativeAsset) AspectRatioImageCreative(com.google.api.ads.admanager.axis.v202202.AspectRatioImageCreative) ImageCreative(com.google.api.ads.admanager.axis.v202202.ImageCreative) Creative(com.google.api.ads.admanager.axis.v202202.Creative) Size(com.google.api.ads.admanager.axis.v202202.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) AspectRatioImageCreative(com.google.api.ads.admanager.axis.v202202.AspectRatioImageCreative) ImageCreative(com.google.api.ads.admanager.axis.v202202.ImageCreative) AspectRatioImageCreative(com.google.api.ads.admanager.axis.v202202.AspectRatioImageCreative)

Example 3 with AspectRatioImageCreative

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

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)1 AspectRatioImageCreative (com.google.api.ads.admanager.axis.v202108.AspectRatioImageCreative)1 Creative (com.google.api.ads.admanager.axis.v202108.Creative)1 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)1 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)1 ImageCreative (com.google.api.ads.admanager.axis.v202108.ImageCreative)1 Size (com.google.api.ads.admanager.axis.v202108.Size)1 AspectRatioImageCreative (com.google.api.ads.admanager.axis.v202111.AspectRatioImageCreative)1 Creative (com.google.api.ads.admanager.axis.v202111.Creative)1 CreativeAsset (com.google.api.ads.admanager.axis.v202111.CreativeAsset)1 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface)1 ImageCreative (com.google.api.ads.admanager.axis.v202111.ImageCreative)1 Size (com.google.api.ads.admanager.axis.v202111.Size)1 AspectRatioImageCreative (com.google.api.ads.admanager.axis.v202202.AspectRatioImageCreative)1 Creative (com.google.api.ads.admanager.axis.v202202.Creative)1 CreativeAsset (com.google.api.ads.admanager.axis.v202202.CreativeAsset)1 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface)1 ImageCreative (com.google.api.ads.admanager.axis.v202202.ImageCreative)1