private static AdGroupAd createAd(
      AdWordsServicesInterface services, AdWordsSession session, AdGroup adGroup)
      throws IOException {
    AdGroupAdServiceInterface adService = services.get(session, AdGroupAdServiceInterface.class);

    ResponsiveDisplayAd ad = new ResponsiveDisplayAd();

    // 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.
    ad.setMarketingImage(uploadImage(services, session, "https://goo.gl/3b9Wfh"));

    ad.setShortHeadline("Travel");
    ad.setLongHeadline("Travel the World");
    ad.setDescription("Take to the air!");
    ad.setBusinessName("Interplanetary Cruises");
    ad.setFinalUrls(new String[] {"http://www.example.com/"});

    // Optional: Call to action text.
    // Valid texts: https://support.google.com/adwords/answer/7005917
    ad.setCallToActionText("Apply Now");

    // Optional: Set dynamic display ad settings, composed of landscape logo
    // image, promotion text, and price prefix.
    DynamicSettings dynamicDisplayAdSettings = createDynamicDisplayAdSettings(services, session);
    ad.setDynamicDisplayAdSettings(dynamicDisplayAdSettings);

    Image optionalImage = uploadImage(services, session, "https://goo.gl/mtt54n");

    // Optional: Create a logo image and set it to the ad.
    ad.setLogoImage(optionalImage);

    // Optional: Create a square marketing image and set it to the ad.
    ad.setSquareMarketingImage(optionalImage);

    // Whitelisted accounts only: Set color settings using hexadecimal values.
    // Set allowFlexibleColor to false if you want your ads to render by always
    // using your colors strictly.
    /*
    ad.setMainColor("#0000ff");
    ad.setAccentColor("#ffff00");
    ad.setAllowFlexibleColor(false);
    */

    // Whitelisted accounts only: Set the format setting that the ad will be
    // served in.
    /*
    ad.setFormatSetting(
        com.google.api.ads.adwords.axis.v201809.cm.DisplayAdFormatSetting.NON_NATIVE);
    */

    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAd(ad);
    adGroupAd.setAdGroupId(adGroup.getId());

    AdGroupAdOperation op = new AdGroupAdOperation();
    op.setOperand(adGroupAd);
    op.setOperator(Operator.ADD);

    AdGroupAdReturnValue result = adService.mutate(new AdGroupAdOperation[] {op});
    return result.getValue(0);
  }
private static AdGroupAd createAd ( AdWordsServicesInterface services , AdWordsSession session , AdGroup adGroup ) throws IOException { AdGroupAdServiceInterface adService = services . get ( session , AdGroupAdServiceInterface . class ) ; ResponsiveDisplayAd ad = new ResponsiveDisplayAd ( ) ; ad . setMarketingImage ( uploadImage ( services , session , "https://goo.gl/3b9Wfh" ) ) ; ad . setShortHeadline ( "Travel" ) ; ad . setLongHeadline ( "Travel the World" ) ; ad . setDescription ( "Take to the air!" ) ; ad . setBusinessName ( "Interplanetary Cruises" ) ; ad . setFinalUrls ( new String [ ] { "http://www.example.com/" } ) ; ad . setCallToActionText ( "Apply Now" ) ; DynamicSettings dynamicDisplayAdSettings = createDynamicDisplayAdSettings ( services , session ) ; ad . setDynamicDisplayAdSettings ( dynamicDisplayAdSettings ) ; Image optionalImage = uploadImage ( services , session , "https://goo.gl/mtt54n" ) ; ad . setLogoImage ( optionalImage ) ; ad . setSquareMarketingImage ( optionalImage ) ; AdGroupAd adGroupAd = new AdGroupAd ( ) ; adGroupAd . setAd ( ad ) ; adGroupAd . setAdGroupId ( adGroup . getId ( ) ) ; AdGroupAdOperation op = new AdGroupAdOperation ( ) ; op . setOperand ( adGroupAd ) ; op . setOperator ( Operator . ADD ) ; AdGroupAdReturnValue result = adService . mutate ( new AdGroupAdOperation [ ] { op } ) ; return result . getValue ( 0 ) ; }
Creates an ad for serving dynamic content in a remarketing campaign.

@param adGroup the ad group under which to create the ad.
@return the ad that was created.
@throws IOException if an image was not able to be loaded.