Search in sources :

Example 1 with Media

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

the class AddGmailAd 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 {
    // This ad format does not allow the creation of an image using the
    // Image.data field. An image must first be created using the MediaService,
    // and Image.mediaId must be populated when creating the ad.
    long logoImageId = uploadImage(adWordsServices, session, "https://goo.gl/mtt54n");
    Image logoImage = new Image();
    logoImage.setMediaId(logoImageId);
    long marketingImageId = uploadImage(adWordsServices, session, "http://goo.gl/3b9Wfh");
    Image adImage = new Image();
    adImage.setMediaId(marketingImageId);
    GmailTeaser teaser = new GmailTeaser();
    teaser.setHeadline("Dream");
    teaser.setDescription("Create your own adventure");
    teaser.setBusinessName("Interplanetary Ships");
    teaser.setLogoImage(logoImage);
    // Create the Gmail ad.
    GmailAd gmailAd = new GmailAd();
    gmailAd.setTeaser(teaser);
    gmailAd.setMarketingImage(adImage);
    gmailAd.setMarketingImageHeadline("Travel");
    gmailAd.setMarketingImageDescription("Take to the skies!");
    gmailAd.setFinalUrls(new String[] { "http://www.example.com" });
    // Create ad group ad for the Gmail ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(gmailAd);
    // Additional properties (non-required).
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(adGroupAd);
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Add Gmail ad.
    AdGroupAdReturnValue returnValue = adGroupAdService.mutate(new AdGroupAdOperation[] { operation });
    if (returnValue.getValue() != null) {
        for (AdGroupAd newAdGroupAd : returnValue.getValue()) {
            System.out.printf("New Gmail ad with ID %d and headline '%s' was added.%n", newAdGroupAd.getAd().getId(), ((GmailAd) newAdGroupAd.getAd()).getTeaser().getHeadline());
        }
    } else {
        System.out.println("No Gmail ads were added.");
    }
}
Also used : GmailAd(com.google.api.ads.adwords.axis.v201809.cm.GmailAd) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) Image(com.google.api.ads.adwords.axis.v201809.cm.Image) GmailTeaser(com.google.api.ads.adwords.axis.v201809.cm.GmailTeaser)

Example 2 with Media

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

the class GetAllImagesAndVideos 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.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the MediaService.
    MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(MediaField.MediaId, MediaField.Width, MediaField.Height, MediaField.MimeType).orderAscBy(MediaField.MediaId).offset(offset).limit(PAGE_SIZE).in(MediaField.Type, "IMAGE", "VIDEO").build();
    MediaPage page = null;
    do {
        // Get all images.
        page = mediaService.get(selector);
        // Display images.
        if (page != null && page.getEntries() != null) {
            for (Media media : page.getEntries()) {
                Map<MediaSize, Dimensions> dimensions = Maps.toMap(media.getDimensions());
                System.out.printf("Media with ID %d, dimensions %s, and MIME type '%s' was found.%n", media.getMediaId(), toString(dimensions.get(MediaSize.FULL)), media.getMediaType());
            }
        } else {
            System.out.println("No images/videos were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
}
Also used : MediaSize(com.google.api.ads.adwords.axis.v201809.cm.MediaSize) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) MediaPage(com.google.api.ads.adwords.axis.v201809.cm.MediaPage) 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) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 3 with Media

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

the class UploadImageAsset 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 AssetService.
    AssetServiceInterface assetService = adWordsServices.get(session, AssetServiceInterface.class);
    // Create the image asset.
    ImageAsset image = new ImageAsset();
    // Optional: Provide a unique friendly name to identify your asset. If you specify the assetName
    // field, then both the asset name and the image being uploaded should be unique, and should not
    // match another ACTIVE asset in this customer account.
    // image.setAssetName("Jupiter Trip #" + System.currentTimeMillis());
    image.setImageData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    // Create the operation.
    AssetOperation operation = new AssetOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(image);
    // Create the asset.
    AssetReturnValue result = assetService.mutate(new AssetOperation[] { operation });
    // Display the results.
    if (result != null && result.getValue() != null && result.getValue().length > 0) {
        Asset newAsset = result.getValue(0);
        System.out.printf("Image asset with ID %d and name '%s' was created.%n", newAsset.getAssetId(), newAsset.getAssetName());
    } else {
        System.out.println("No image asset was created.");
    }
}
Also used : AssetReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AssetReturnValue) Asset(com.google.api.ads.adwords.axis.v201809.cm.Asset) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset) AssetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset) AssetOperation(com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)

Example 4 with Media

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

the class UploadImage 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 image.
    Image image = new Image();
    image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    image.setType(MediaMediaType.IMAGE);
    Media[] media = new Media[] { image };
    // Upload image.
    Media[] result = mediaService.upload(media);
    // Display images.
    image = (Image) result[0];
    Map<MediaSize, Dimensions> dimensions = Maps.toMap(image.getDimensions());
    System.out.printf("Image with ID %d, dimensions %dx%d, and MIME type '%s' was " + "uploaded.%n", image.getMediaId(), dimensions.get(MediaSize.FULL).getWidth(), dimensions.get(MediaSize.FULL).getHeight(), image.getMediaType());
}
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) Image(com.google.api.ads.adwords.axis.v201809.cm.Image)

Example 5 with Media

use of com.google.api.ads.adwords.axis.v201809.cm.Media 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)

Aggregations

Image (com.google.api.ads.adwords.axis.v201809.cm.Image)5 MediaServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface)5 Dimensions (com.google.api.ads.adwords.axis.v201809.cm.Dimensions)4 Media (com.google.api.ads.adwords.axis.v201809.cm.Media)4 MediaSize (com.google.api.ads.adwords.axis.v201809.cm.MediaSize)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)2 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)2 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)2 MediaBundle (com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 Asset (com.google.api.ads.adwords.axis.v201809.cm.Asset)1 AssetOperation (com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)1 AssetReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AssetReturnValue)1 AssetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface)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 GmailAd (com.google.api.ads.adwords.axis.v201809.cm.GmailAd)1