Search in sources :

Example 11 with Image

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

the class AddGmailAd method uploadImage.

/**
 * Uploads an image.
 */
private static long uploadImage(AdWordsServicesInterface adWordsServices, AdWordsSession session, String url) throws IOException {
    MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
    // Create image.
    Image image = new Image();
    image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl(url));
    image.setType(MediaMediaType.IMAGE);
    Media[] media = new Media[] { image };
    // Upload image.
    Media[] result = mediaService.upload(media);
    return result[0].getMediaId();
}
Also used : MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Media(com.google.api.ads.adwords.axis.v201809.cm.Media) Image(com.google.api.ads.adwords.axis.v201809.cm.Image)

Example 12 with Image

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

the class AddMultiAssetResponsiveDisplayAd method createAssetLinkForImageAsset.

/**
 * Creates an {@link AssetLink} containing a {@link ImageAsset} with the specified asset ID.
 *
 * @param assetId ID of the image asset.
 * @return a new {@link AssetLink}
 */
private static AssetLink createAssetLinkForImageAsset(long assetId) {
    AssetLink assetLink = new AssetLink();
    ImageAsset imageAsset = new ImageAsset();
    imageAsset.setAssetId(assetId);
    assetLink.setAsset(imageAsset);
    return assetLink;
}
Also used : AssetLink(com.google.api.ads.adwords.axis.v201809.cm.AssetLink) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset)

Example 13 with Image

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

the class AddUniversalAppCampaign 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 CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create the campaign.
    Campaign campaign = new Campaign();
    campaign.setName("Interplanetary Cruise App #" + System.currentTimeMillis());
    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    campaign.setStatus(CampaignStatus.PAUSED);
    // Set the advertising channel and subchannel types for universal app campaigns.
    campaign.setAdvertisingChannelType(AdvertisingChannelType.MULTI_CHANNEL);
    campaign.setAdvertisingChannelSubType(AdvertisingChannelSubType.UNIVERSAL_APP_CAMPAIGN);
    // Set the campaign's bidding strategy. universal app campaigns
    // only support TARGET_CPA bidding strategy.
    BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
    biddingConfig.setBiddingStrategyType(BiddingStrategyType.TARGET_CPA);
    // Set the target CPA to $1 / app install.
    TargetCpaBiddingScheme biddingScheme = new TargetCpaBiddingScheme();
    biddingScheme.setTargetCpa(new Money());
    biddingScheme.getTargetCpa().setMicroAmount(1000000L);
    biddingConfig.setBiddingScheme(biddingScheme);
    campaign.setBiddingStrategyConfiguration(biddingConfig);
    // Set the campaign's budget.
    campaign.setBudget(new Budget());
    campaign.getBudget().setBudgetId(createBudget(adWordsServices, session));
    // Optional: Set the start date.
    campaign.setStartDate(DateTime.now().plusDays(1).toString("yyyyMMdd"));
    // Optional: Set the end date.
    campaign.setEndDate(DateTime.now().plusYears(1).toString("yyyyMMdd"));
    // Set the campaign's assets and ad text ideas. These values will be used to
    // generate ads.
    UniversalAppCampaignSetting universalAppSetting = new UniversalAppCampaignSetting();
    universalAppSetting.setAppId("com.labpixies.colordrips");
    universalAppSetting.setAppVendor(MobileApplicationVendor.VENDOR_GOOGLE_MARKET);
    universalAppSetting.setDescription1("A cool puzzle game");
    universalAppSetting.setDescription2("Remove connected blocks");
    universalAppSetting.setDescription3("3 difficulty levels");
    universalAppSetting.setDescription4("4 colorful fun skins");
    // Optional: You can set up to 20 image assets for your campaign.
    // See UploadImage.java for an example on how to upload images.
    // 
    // universalAppSetting.setImageMediaIds(new long[] { INSERT_IMAGE_MEDIA_ID_HERE });
    // Optimize this campaign for getting new users for your app.
    universalAppSetting.setUniversalAppBiddingStrategyGoalType(UniversalAppBiddingStrategyGoalType.OPTIMIZE_FOR_INSTALL_CONVERSION_VOLUME);
    // If you select the OPTIMIZE_FOR_IN_APP_CONVERSION_VOLUME goal type, then also specify
    // your in-app conversion types so AdWords can focus your campaign on people who are
    // most likely to complete the corresponding in-app actions.
    // Conversion type IDs can be retrieved using ConversionTrackerService.get.
    // 
    // campaign.selectiveOptimization = new SelectiveOptimization();
    // campaign.selectiveOptimization.conversionTypeIds =
    // new long[] { INSERT_CONVERSION_TYPE_ID_1_HERE, INSERT_CONVERSION_TYPE_ID_2_HERE };
    // Optional: Set the campaign settings for Advanced location options.
    GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
    geoSetting.setPositiveGeoTargetType(GeoTargetTypeSettingPositiveGeoTargetType.LOCATION_OF_PRESENCE);
    geoSetting.setNegativeGeoTargetType(GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE);
    campaign.setSettings(new Setting[] { universalAppSetting, geoSetting });
    // Create the operation.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    CampaignOperation[] operations = new CampaignOperation[] { operation };
    // Add the campaign.
    CampaignReturnValue result = campaignService.mutate(operations);
    // Display the results.
    for (Campaign newCampaign : result.getValue()) {
        System.out.printf("Universal app campaign with name '%s' and ID %d was added.%n", newCampaign.getName(), newCampaign.getId());
        // Optional: Set the campaign's location and language targeting. No other targeting
        // criteria can be used for universal app campaigns.
        setCampaignTargetingCriteria(newCampaign, adWordsServices, session);
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) UniversalAppCampaignSetting(com.google.api.ads.adwords.axis.v201809.cm.UniversalAppCampaignSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) TargetCpaBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.TargetCpaBiddingScheme) GeoTargetTypeSetting(com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting)

Example 14 with Image

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

the class AddShoppingDynamicRemarketingCampaign method uploadImage.

/**
 * Uploads the image from the specified {@code url}.
 *
 * @return the {@code Image} that was uploaded.
 * @throws IOException if the image cannot be loaded.
 */
private static Image uploadImage(AdWordsServicesInterface services, AdWordsSession session, String url) throws IOException {
    Image image = new Image();
    image.setType(MediaMediaType.IMAGE);
    image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl(url));
    MediaServiceInterface mediaService = services.get(session, MediaServiceInterface.class);
    return (Image) mediaService.upload(new Media[] { image })[0];
}
Also used : MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Image(com.google.api.ads.adwords.axis.v201809.cm.Image)

Example 15 with Image

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

the class AddShoppingDynamicRemarketingCampaign method createDynamicDisplayAdSettings.

/**
 * Creates the additional content (images, promo text, etc.) supported by dynamic ads.
 *
 * @return the DynamicSettings object to be used.
 */
private static DynamicSettings createDynamicDisplayAdSettings(AdWordsServicesInterface services, AdWordsSession session) throws IOException {
    Image logo = uploadImage(services, session, "https://goo.gl/dEvQeF");
    DynamicSettings dynamicSettings = new DynamicSettings();
    dynamicSettings.setLandscapeLogoImage(logo);
    dynamicSettings.setPricePrefix("as low as");
    dynamicSettings.setPromoText("Free shipping!");
    return dynamicSettings;
}
Also used : Image(com.google.api.ads.adwords.axis.v201809.cm.Image) DynamicSettings(com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings)

Aggregations

Image (com.google.api.ads.adwords.axis.v201809.cm.Image)9 MediaServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface)5 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)4 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)4 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)4 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)4 AssetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface)4 DynamicSettings (com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings)4 ImageAsset (com.google.api.ads.adwords.axis.v201809.cm.ImageAsset)4 Media (com.google.api.ads.adwords.axis.v201809.cm.Media)4 AssetOperation (com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)3 Parameter (com.beust.jcommander.Parameter)2 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroupAdStatus (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdStatus)2 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)2 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 Asset (com.google.api.ads.adwords.axis.v201809.cm.Asset)2 AssetLink (com.google.api.ads.adwords.axis.v201809.cm.AssetLink)2 Dimensions (com.google.api.ads.adwords.axis.v201809.cm.Dimensions)2