Search in sources :

Example 6 with Creative

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

the class GetAllLicas 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 LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to get all LICAs.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("lineItemId ASC, creativeId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // 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 was found.%n", i++, lica.getLineItemId(), lica.getCreativeSetId());
                } else {
                    System.out.printf("%d) LICA with line item ID %d and creative ID %d was found.%n", i++, lica.getLineItemId(), lica.getCreativeId());
                }
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemCreativeAssociation(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItemCreativeAssociationPage(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationPage) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface)

Example 7 with Creative

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

the class CreateNativeCreatives 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);
    // Use the system defined native app install creative template.
    long nativeAppInstallTemplateId = 10004400L;
    // Use 1x1 as the size for native creatives.
    Size size = new Size();
    size.setWidth(1);
    size.setHeight(1);
    size.setIsAspectRatio(false);
    // Create a native app install creative for the Pie Noon app.
    TemplateCreative nativeAppInstallCreative = new TemplateCreative();
    nativeAppInstallCreative.setName("Native creative #" + new Random().nextInt(Integer.MAX_VALUE));
    nativeAppInstallCreative.setAdvertiserId(advertiserId);
    nativeAppInstallCreative.setDestinationUrl("https://play.google.com/store/apps/details?id=com.google.fpl.pie_noon");
    nativeAppInstallCreative.setCreativeTemplateId(nativeAppInstallTemplateId);
    nativeAppInstallCreative.setSize(size);
    List<BaseCreativeTemplateVariableValue> templateVariables = new ArrayList<>();
    // Set the headline.
    StringCreativeTemplateVariableValue headlineVariableValue = new StringCreativeTemplateVariableValue();
    headlineVariableValue.setUniqueName("Headline");
    headlineVariableValue.setValue("Pie Noon");
    templateVariables.add(headlineVariableValue);
    // Set the body text.
    StringCreativeTemplateVariableValue bodyVariableValue = new StringCreativeTemplateVariableValue();
    bodyVariableValue.setUniqueName("Body");
    bodyVariableValue.setValue("Try multi-screen mode!");
    templateVariables.add(bodyVariableValue);
    // Set the image asset.
    AssetCreativeTemplateVariableValue imageVariableValue = new AssetCreativeTemplateVariableValue();
    imageVariableValue.setUniqueName("Image");
    CreativeAsset imageAsset = new CreativeAsset();
    imageAsset.setFileName("image" + new Random().nextInt(Integer.MAX_VALUE) + ".png");
    imageAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://lh4.ggpht.com/" + "GIGNKdGHMEHFDw6TM2bgAUDKPQQRIReKZPqEpMeEhZOPYnTdOQGaSpGSEZflIFs0iw=h300"));
    imageVariableValue.setAsset(imageAsset);
    templateVariables.add(imageVariableValue);
    // Set the price.
    StringCreativeTemplateVariableValue priceVariableValue = new StringCreativeTemplateVariableValue();
    priceVariableValue.setUniqueName("Price");
    priceVariableValue.setValue("Free");
    templateVariables.add(priceVariableValue);
    // Set app icon image asset.
    AssetCreativeTemplateVariableValue appIconVariableValue = new AssetCreativeTemplateVariableValue();
    appIconVariableValue.setUniqueName("Appicon");
    CreativeAsset appIconAsset = new CreativeAsset();
    appIconAsset.setFileName("icon" + new Random().nextInt(Integer.MAX_VALUE) + ".png");
    appIconAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://lh6.ggpht.com/" + "Jzvjne5CLs6fJ1MHF-XeuUfpABzl0YNMlp4RpHnvPRCIj4--eTDwtyouwUDzVVekXw=w300"));
    appIconVariableValue.setAsset(appIconAsset);
    templateVariables.add(appIconVariableValue);
    // Set the call to action text.
    StringCreativeTemplateVariableValue callToActionVariableValue = new StringCreativeTemplateVariableValue();
    callToActionVariableValue.setUniqueName("Calltoaction");
    callToActionVariableValue.setValue("Install");
    templateVariables.add(callToActionVariableValue);
    // Set the star rating.
    StringCreativeTemplateVariableValue starRatingVariableValue = new StringCreativeTemplateVariableValue();
    starRatingVariableValue.setUniqueName("Starrating");
    starRatingVariableValue.setValue("4");
    templateVariables.add(starRatingVariableValue);
    // Set the store type.
    StringCreativeTemplateVariableValue storeVariableValue = new StringCreativeTemplateVariableValue();
    storeVariableValue.setUniqueName("Store");
    storeVariableValue.setValue("Google Play");
    templateVariables.add(storeVariableValue);
    // Set the deep link URL.
    UrlCreativeTemplateVariableValue deepLinkVariableValue = new UrlCreativeTemplateVariableValue();
    deepLinkVariableValue.setUniqueName("DeeplinkclickactionURL");
    deepLinkVariableValue.setValue("market://details?id=com.google.fpl.pie_noon");
    templateVariables.add(deepLinkVariableValue);
    nativeAppInstallCreative.setCreativeTemplateVariableValues(templateVariables.toArray(new BaseCreativeTemplateVariableValue[templateVariables.size()]));
    // Create the creative on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { nativeAppInstallCreative });
    for (Creative createdCreative : creatives) {
        System.out.printf("A native creative with ID %d and name '%s' was" + " created and can be previewed at: %s%n", createdCreative.getId(), createdCreative.getName(), createdCreative.getPreviewUrl());
    }
}
Also used : TemplateCreative(com.google.api.ads.admanager.axis.v202111.TemplateCreative) Size(com.google.api.ads.admanager.axis.v202111.Size) ArrayList(java.util.ArrayList) StringCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.StringCreativeTemplateVariableValue) UrlCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.UrlCreativeTemplateVariableValue) 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) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface) AssetCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.AssetCreativeTemplateVariableValue) BaseCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202111.BaseCreativeTemplateVariableValue)

Example 8 with Creative

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

Example 9 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.v202111.HasDestinationUrlCreative) HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202111.HasDestinationUrlCreative) 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 10 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.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)

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