Search in sources :

Example 31 with Creative

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

the class GetCreativeSetsForMasterCreative method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param masterCreativeId the ID of the master creative.
 * @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) throws RemoteException {
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to select creative sets.
    StatementBuilder statementBuilder = new StatementBuilder().where("masterCreativeId = :masterCreativeId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("masterCreativeId", masterCreativeId);
    // Retrieve a small amount of creative sets at a time, paging through
    // until all creative sets have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative set.
            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.v202108.StatementBuilder) CreativeSetPage(com.google.api.ads.admanager.axis.v202108.CreativeSetPage) CreativeSet(com.google.api.ads.admanager.axis.v202108.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeSetServiceInterface)

Example 32 with Creative

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

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

Example 33 with Creative

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

the class CreateCreatives 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 an image creative.
    ImageCreative imageCreative = new ImageCreative();
    imageCreative.setName("Image creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageCreative.setAdvertiserId(advertiserId);
    imageCreative.setDestinationUrl("http://google.com");
    imageCreative.setSize(size);
    // Create image asset.
    CreativeAsset creativeAsset = new CreativeAsset();
    creativeAsset.setFileName("image.jpg");
    creativeAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    creativeAsset.setSize(size);
    imageCreative.setPrimaryImageAsset(creativeAsset);
    // Create an image redirect creative.
    ImageRedirectCreative imageRedirectCreative = new ImageRedirectCreative();
    imageRedirectCreative.setName("Image redirect creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageRedirectCreative.setAdvertiserId(advertiserId);
    imageRedirectCreative.setDestinationUrl("http://google.com");
    imageRedirectCreative.setImageUrl("https://goo.gl/3b9Wfh");
    imageRedirectCreative.setSize(size);
    // Create the creatives on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { imageCreative, imageRedirectCreative });
    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 : Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202108.CreativeAsset) Creative(com.google.api.ads.admanager.axis.v202108.Creative) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202108.ImageRedirectCreative) 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) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202108.ImageRedirectCreative) ImageCreative(com.google.api.ads.admanager.axis.v202108.ImageCreative)

Example 34 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.v202108.CustomCreativeAsset) CustomCreative(com.google.api.ads.admanager.axis.v202108.CustomCreative) Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202108.CreativeAsset) CustomCreativeAsset(com.google.api.ads.admanager.axis.v202108.CustomCreativeAsset) Creative(com.google.api.ads.admanager.axis.v202108.Creative) CustomCreative(com.google.api.ads.admanager.axis.v202108.CustomCreative) Size(com.google.api.ads.admanager.axis.v202108.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)

Example 35 with Creative

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

the class DeactivateLicas method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to deactivate LICAs for.
 * @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 lineItemId) throws RemoteException {
    // Get the LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to select all LICAs for a line item.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE lineItemId = :lineItemId").orderBy("lineItemId ASC, creativeId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lineItemId", lineItemId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get LICAs by statement.
        LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItemCreativeAssociation lica : page.getResults()) {
                if (lica.getCreativeSetId() != null) {
                    System.out.printf("%d) LICA with line item ID %d and creative " + "set ID %d will be deactivated.%n", i++, lica.getLineItemId(), lica.getCreativeSetId());
                } else {
                    System.out.printf("%d) LICA with line item ID %d and creative ID %d will be deactivated.%n", i++, lica.getLineItemId(), lica.getCreativeId());
                }
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of LICAs to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations();
        // Perform action.
        UpdateResult result = licaService.performLineItemCreativeAssociationAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of LICAs deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No LICAs were deactivated.");
        }
    }
}
Also used : LineItemCreativeAssociation(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LineItemCreativeAssociationPage(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationPage) DeactivateLineItemCreativeAssociations(com.google.api.ads.admanager.axis.v202108.DeactivateLineItemCreativeAssociations) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

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