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());
}
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());
}
}
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());
}
Aggregations