Search in sources :

Example 31 with Creative

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

the class GetAllCreatives 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 CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create a statement to get all creatives.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creatives by statement.
        CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            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.v202202.Creative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202202.CreativePage)

Example 32 with Creative

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

the class UpdateCreatives method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeId the ID of the creative to update.
 * @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 only select a single creative by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeId);
    // Get the creative.
    CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
    Creative creative = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Only update the destination URL if it has one.
    if (creative instanceof HasDestinationUrlCreative) {
        HasDestinationUrlCreative hasDestinationUrlCreative = (HasDestinationUrlCreative) creative;
        // Update the destination URL of the creative.
        hasDestinationUrlCreative.setDestinationUrl("http://news.google.com");
        // Update the creative on the server.
        Creative[] creatives = creativeService.updateCreatives(new Creative[] { creative });
        for (Creative updatedCreative : creatives) {
            System.out.printf("Creative with ID %d and name '%s' was updated.%n", updatedCreative.getId(), updatedCreative.getName());
        }
    } else {
        System.out.println("No creatives were updated.");
    }
}
Also used : HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202202.HasDestinationUrlCreative) HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202202.HasDestinationUrlCreative) Creative(com.google.api.ads.admanager.axis.v202202.Creative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202202.CreativePage)

Example 33 with Creative

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

the class GetAllCreativeSets 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 CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to get all creativeSets.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative sets by statement.
        CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeSet creativeSet : page.getResults()) {
                System.out.printf("%d) Creative set with ID %d and name '%s' was found.%n", i++, creativeSet.getId(), creativeSet.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CreativeSetPage(com.google.api.ads.admanager.axis.v202202.CreativeSetPage) CreativeSet(com.google.api.ads.admanager.axis.v202202.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeSetServiceInterface)

Example 34 with Creative

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

the class CreateCreativeWrappers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the label that can be associated with creative wrappers.
 * @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 labelId) throws RemoteException {
    // Get the CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a creative wrapper.
    CreativeWrapper innerCreativeWrapper = new CreativeWrapper();
    // A label can only be associated with one creative wrapper.
    innerCreativeWrapper.setLabelId(labelId);
    innerCreativeWrapper.setOrdering(CreativeWrapperOrdering.INNER);
    innerCreativeWrapper.setHtmlHeader("<b>My creative wrapper header</b>");
    innerCreativeWrapper.setHtmlFooter("<b>My creative wrapper footer</b>");
    // Create the creative wrapper on the server.
    CreativeWrapper[] creativeWrappers = creativeWrapperService.createCreativeWrappers(new CreativeWrapper[] { innerCreativeWrapper });
    for (CreativeWrapper createdCreativeWrapper : creativeWrappers) {
        System.out.printf("Creative wrapper with ID %d applying to label ID %d was created.%n", createdCreativeWrapper.getId(), createdCreativeWrapper.getLabelId());
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202202.CreativeWrapper) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface)

Example 35 with Creative

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

Aggregations

Random (java.util.Random)19 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)18 Size (com.google.api.ads.admanager.axis.v202202.Size)12 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.v202202.LineItemCreativeAssociationServiceInterface)6 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)5 Size (com.google.api.ads.admanager.axis.v202108.Size)5 CreativeAsset (com.google.api.ads.admanager.axis.v202111.CreativeAsset)5 Size (com.google.api.ads.admanager.axis.v202111.Size)5 AdUnitTargeting (com.google.api.ads.admanager.axis.v202202.AdUnitTargeting)5 CreativeAsset (com.google.api.ads.admanager.axis.v202202.CreativeAsset)5 CreativePlaceholder (com.google.api.ads.admanager.axis.v202202.CreativePlaceholder)5 CreativeWrapper (com.google.api.ads.admanager.axis.v202202.CreativeWrapper)5 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface)5 Goal (com.google.api.ads.admanager.axis.v202202.Goal)5