Search in sources :

Example 16 with Creative

use of com.google.api.ads.admanager.axis.v202202.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.v202202.TemplateCreative) LongCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202202.LongCreativeTemplateVariableValue) Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202202.CreativeAsset) TemplateCreative(com.google.api.ads.admanager.axis.v202202.TemplateCreative) 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) StringCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202202.StringCreativeTemplateVariableValue) AssetCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202202.AssetCreativeTemplateVariableValue) UrlCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202202.UrlCreativeTemplateVariableValue)

Example 17 with Creative

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

the class UpdateCreativeSets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeSetId the ID of the creative set to update.
 * @param companionCreativeId the ID of the companion creative to add to 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 creativeSetId, long companionCreativeId) throws RemoteException {
    // Get the CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to only select a single creative set by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeSetId);
    // Get the creative set.
    CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
    CreativeSet creativeSet = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Add the companion creative to the creative set.
    creativeSet.setCompanionCreativeIds(Longs.concat(creativeSet.getCompanionCreativeIds(), new long[] { companionCreativeId }));
    // Update the creative set on the server.
    CreativeSet updatedCreativeSet = creativeSetService.updateCreativeSet(creativeSet);
    System.out.printf("A creative set with ID %d, master creative ID %d, " + "and companion creative IDs [%s] was updated.", updatedCreativeSet.getId(), updatedCreativeSet.getMasterCreativeId(), Longs.join(",", updatedCreativeSet.getCompanionCreativeIds()));
}
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 18 with Creative

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

the class GetSystemDefinedCreativeTemplates 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 {
    CreativeTemplateServiceInterface creativeTemplateService = adManagerServices.get(session, CreativeTemplateServiceInterface.class);
    // Create a statement to select creative templates.
    StatementBuilder statementBuilder = new StatementBuilder().where("type = :type").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", CreativeTemplateType.SYSTEM_DEFINED.toString());
    // Retrieve a small amount of creative templates at a time, paging through
    // until all creative templates have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativeTemplatePage page = creativeTemplateService.getCreativeTemplatesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative template.
            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.v202202.CreativeTemplateServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CreativeTemplate(com.google.api.ads.admanager.axis.v202202.CreativeTemplate) CreativeTemplatePage(com.google.api.ads.admanager.axis.v202202.CreativeTemplatePage)

Example 19 with Creative

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

the class DeactivateCreativeWrappersForLabel method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the creative wrapper label to deactivate.
 * @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 statement to select the active creative wrappers for the
    // given label.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE status = :status AND labelId = :labelId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString()).withBindVariableValue("labelId", labelId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative wrappers by statement.
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d applying to label ID" + " %d will be deactivated.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of creative wrappers to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        DeactivateCreativeWrappers action = new DeactivateCreativeWrappers();
        // Perform action.
        UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of creative wrappers deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No creative wrappers were deactivated.");
        }
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202202.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202202.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) DeactivateCreativeWrappers(com.google.api.ads.admanager.axis.v202202.DeactivateCreativeWrappers) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 20 with Creative

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

the class GetActiveCreativeWrappers 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 {
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select creative wrappers.
    StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString());
    // Retrieve a small amount of creative wrappers at a time, paging through
    // until all creative wrappers have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative wrapper.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d and label ID %d was found.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202202.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202202.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface)

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