Search in sources :

Example 6 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class AddProductScope method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the shopping campaign.
 * @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(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId) throws RemoteException {
    // Get the campaign criterion service.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    ProductScope productScope = new ProductScope();
    // This set of dimensions is for demonstration purposes only. It would be
    // extremely unlikely that you want to include so many dimensions in your
    // product scope.
    ProductBrand productBrand = new ProductBrand();
    productBrand.setValue("Nexus");
    ProductCanonicalCondition productCanonicalCondition = new ProductCanonicalCondition();
    productCanonicalCondition.setCondition(ProductCanonicalConditionCondition.NEW);
    ProductCustomAttribute productCustomAttribute = new ProductCustomAttribute();
    productCustomAttribute.setType(ProductDimensionType.CUSTOM_ATTRIBUTE_0);
    productCustomAttribute.setValue("my attribute value");
    ProductOfferId productOfferId = new ProductOfferId();
    productOfferId.setValue("book1");
    ProductType productTypeLevel1Media = new ProductType();
    productTypeLevel1Media.setType(ProductDimensionType.PRODUCT_TYPE_L1);
    productTypeLevel1Media.setValue("Media");
    ProductType productTypeLevel2Books = new ProductType();
    productTypeLevel2Books.setType(ProductDimensionType.PRODUCT_TYPE_L2);
    productTypeLevel2Books.setValue("Books");
    // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
    // category. You can retrieve IDs for categories from the ConstantDataService.
    // See the 'GetProductCategoryTaxonomy' example for more details.
    ProductBiddingCategory productBiddingCategory = new ProductBiddingCategory();
    productBiddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
    productBiddingCategory.setValue(-5914235892932915235L);
    productScope.setDimensions(new ProductDimension[] { productBrand, productCanonicalCondition, productCustomAttribute, productOfferId, productTypeLevel1Media, productTypeLevel2Books, productBiddingCategory });
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(campaignId);
    campaignCriterion.setCriterion(productScope);
    // Create operation.
    CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
    criterionOperation.setOperand(campaignCriterion);
    criterionOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation });
    // Display the result.
    System.out.printf("Created a ProductScope criterion with ID %d.%n", result.getValue(0).getCriterion().getId());
}
Also used : CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductOfferId(com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition) ProductScope(com.google.api.ads.adwords.axis.v201809.cm.ProductScope) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ProductCustomAttribute(com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute) ProductType(com.google.api.ads.adwords.axis.v201809.cm.ProductType) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) ProductBiddingCategory(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)

Example 7 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class AddHtml5Ad method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where the ad will be created.
 * @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(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws IOException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Create the template ad.
    TemplateAd html5Ad = new TemplateAd();
    html5Ad.setName("Ad for HTML5");
    html5Ad.setTemplateId(419L);
    html5Ad.setFinalUrls(new String[] { "http://example.com/html5" });
    html5Ad.setDisplayUrl("example.com/html5");
    Dimensions dimensions = new Dimensions();
    dimensions.setWidth(300);
    dimensions.setHeight(250);
    html5Ad.setDimensions(dimensions);
    // The HTML5 zip file contains all the HTML, CSS, and images needed for the
    // HTML5 ad. For help on creating an HTML5 zip file, check out Google Web
    // Designer (https://www.google.com/webdesigner/).
    byte[] html5Zip = com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/9Y7qI2");
    // Create a media bundle containing the zip file with all the HTML5 components.
    // NOTE: You may also upload an HTML5 zip using MediaService.upload()
    // and simply set the mediaId field below. See UploadMediaBundle.java for an example.
    MediaBundle mediaBundle = new MediaBundle();
    mediaBundle.setData(html5Zip);
    mediaBundle.setEntryPoint("carousel/index.html");
    mediaBundle.setType(MediaMediaType.MEDIA_BUNDLE);
    // Create the template elements for the ad. You can refer to
    // https://developers.google.com/adwords/api/docs/appendix/templateads
    // for the list of available template fields.
    TemplateElementField media = new TemplateElementField();
    media.setName("Custom_layout");
    media.setFieldMedia(mediaBundle);
    media.setType(TemplateElementFieldType.MEDIA_BUNDLE);
    TemplateElementField layout = new TemplateElementField();
    layout.setName("layout");
    layout.setFieldText("Custom");
    layout.setType(TemplateElementFieldType.ENUM);
    TemplateElement adData = new TemplateElement();
    adData.setUniqueName("adData");
    adData.setFields(new TemplateElementField[] { media, layout });
    html5Ad.setTemplateElements(new TemplateElement[] { adData });
    // Create the AdGroupAd.
    AdGroupAd html5AdGroupAd = new AdGroupAd();
    html5AdGroupAd.setAdGroupId(adGroupId);
    html5AdGroupAd.setAd(html5Ad);
    // Optional: Set the status.
    html5AdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create the operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(html5AdGroupAd);
    // Create the ads.
    AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] { operation });
    for (AdGroupAd adGroupAd : result.getValue()) {
        System.out.printf("New HTML5 ad with ID %d and display url '%s' was created.%n", adGroupAd.getAd().getId(), adGroupAd.getAd().getDisplayUrl());
    }
}
Also used : TemplateElementField(com.google.api.ads.adwords.axis.v201809.cm.TemplateElementField) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) TemplateAd(com.google.api.ads.adwords.axis.v201809.cm.TemplateAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) TemplateElement(com.google.api.ads.adwords.axis.v201809.cm.TemplateElement) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) Dimensions(com.google.api.ads.adwords.axis.v201809.cm.Dimensions) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) MediaBundle(com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)

Example 8 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class UploadMediaBundle method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices 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.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws IOException {
    // Get the MediaService.
    MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
    // Create HTML5 media.
    byte[] html5Zip = com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/9Y7qI2");
    // Create a media bundle containing the zip file with all the HTML5 components.
    MediaBundle mediaBundle = new MediaBundle();
    mediaBundle.setData(html5Zip);
    mediaBundle.setType(MediaMediaType.MEDIA_BUNDLE);
    // Upload HTML5 zip.
    mediaBundle = (MediaBundle) mediaService.upload(new Media[] { mediaBundle })[0];
    // Display HTML5 zip.
    Map<MediaSize, Dimensions> dimensions = Maps.toMap(mediaBundle.getDimensions());
    System.out.printf("HTML5 media with ID %d, dimensions '%dx%d', and MIME type '%s' " + "was uploaded.%n", mediaBundle.getMediaId(), dimensions.get(MediaSize.FULL).getWidth(), dimensions.get(MediaSize.FULL).getHeight(), mediaBundle.getMimeType());
}
Also used : MediaSize(com.google.api.ads.adwords.axis.v201809.cm.MediaSize) MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Media(com.google.api.ads.adwords.axis.v201809.cm.Media) Dimensions(com.google.api.ads.adwords.axis.v201809.cm.Dimensions) MediaBundle(com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)

Aggregations

Dimensions (com.google.api.ads.adwords.axis.v201809.cm.Dimensions)4 Media (com.google.api.ads.adwords.axis.v201809.cm.Media)3 MediaServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface)3 MediaSize (com.google.api.ads.adwords.axis.v201809.cm.MediaSize)3 ProductDimension (com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)3 MediaBundle (com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)2 ProductBrand (com.google.api.ads.adwords.axis.v201809.cm.ProductBrand)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 NodeDifference (com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionNodeDiffer.NodeDifference)1 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)1 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)1 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)1 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)1 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 Image (com.google.api.ads.adwords.axis.v201809.cm.Image)1 MediaPage (com.google.api.ads.adwords.axis.v201809.cm.MediaPage)1 ProductBiddingCategory (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)1