2020import com .google .ads .googleads .examples .utils .CodeSampleParams ;
2121import com .google .ads .googleads .lib .GoogleAdsClient ;
2222import com .google .ads .googleads .lib .utils .FieldMasks ;
23+ import com .google .ads .googleads .v11 .common .AdTextAsset ;
24+ import com .google .ads .googleads .v11 .enums .ServedAssetFieldTypeEnum .ServedAssetFieldType ;
2325import com .google .ads .googleads .v11 .errors .GoogleAdsError ;
2426import com .google .ads .googleads .v11 .errors .GoogleAdsException ;
2527import com .google .ads .googleads .v11 .resources .Ad ;
3234import java .io .FileNotFoundException ;
3335import java .io .IOException ;
3436
35- /** Updates an expanded text ad. To get expanded text ads, run GetExpandedTextAds . */
36- public class UpdateExpandedTextAd {
37+ /** Updates a responsive search ad. To get responsive search ads, run GetResponsiveSearchAds . */
38+ public class UpdateResponsiveSearchAd {
3739
38- private static class UpdateExpandedTextAdParams extends CodeSampleParams {
40+ private static class UpdateResponsiveSearchAdParams extends CodeSampleParams {
3941
4042 @ Parameter (names = ArgumentNames .CUSTOMER_ID , required = true )
4143 private Long customerId ;
@@ -45,7 +47,7 @@ private static class UpdateExpandedTextAdParams extends CodeSampleParams {
4547 }
4648
4749 public static void main (String [] args ) {
48- UpdateExpandedTextAdParams params = new UpdateExpandedTextAdParams ();
50+ UpdateResponsiveSearchAdParams params = new UpdateResponsiveSearchAdParams ();
4951 if (!params .parseArguments (args )) {
5052
5153 // Either pass the required parameters for this example on the command line, or insert them
@@ -67,7 +69,7 @@ public static void main(String[] args) {
6769 }
6870
6971 try {
70- new UpdateExpandedTextAd ().runExample (googleAdsClient , params .customerId , params .adId );
72+ new UpdateResponsiveSearchAd ().runExample (googleAdsClient , params .customerId , params .adId );
7173 } catch (GoogleAdsException gae ) {
7274 // GoogleAdsException is the base class for most exceptions thrown by an API request.
7375 // Instances of this exception have a message and a GoogleAdsFailure that contains a
@@ -91,7 +93,7 @@ public static void main(String[] args) {
9193 * @param customerId the customer ID to update.
9294 * @param adId the ad ID to update.
9395 */
94- // [START update_expanded_text_ad ]
96+ // [START update_responsive_search_ad ]
9597 private void runExample (GoogleAdsClient googleAdsClient , long customerId , long adId ) {
9698 // Creates an AdOperation to update an ad.
9799 AdOperation .Builder adOperation = AdOperation .newBuilder ();
@@ -104,12 +106,23 @@ private void runExample(GoogleAdsClient googleAdsClient, long customerId, long a
104106 .addFinalUrls ("http://www.example.com/" )
105107 .addFinalMobileUrls ("http://www.example.com/mobile" );
106108
107- // Sets the expanded text ad properties to update on the ad.
109+ // Sets the responsive search ad properties to update on the ad.
108110 adBuilder
109- .getExpandedTextAdBuilder ()
110- .setHeadlinePart1 ("Cruise to Pluto #" + getShortPrintableDateTime ())
111- .setHeadlinePart2 ("Tickets on sale now" )
112- .setDescription ("Best space cruise ever." );
111+ .getResponsiveSearchAdBuilder ()
112+ .addAllHeadlines (
113+ ImmutableList .of (
114+ AdTextAsset .newBuilder ()
115+ .setText ("Cruise to Pluto #" + getShortPrintableDateTime ())
116+ .setPinnedField (ServedAssetFieldType .HEADLINE_1 )
117+ .build (),
118+ AdTextAsset .newBuilder ().setText ("Tickets on sale now" ).build (),
119+ AdTextAsset .newBuilder ().setText ("Buy your ticket now" ).build ()))
120+ .addAllDescriptions (
121+ ImmutableList .of (
122+ AdTextAsset .newBuilder ().setText ("Best space cruise ever." ).build (),
123+ AdTextAsset .newBuilder ()
124+ .setText ("The most wonderful space experience you will ever have." )
125+ .build ()));
113126
114127 // Sets the update mask (the fields which will be modified) to be all the fields we set above.
115128 adOperation .setUpdateMask (FieldMasks .allSetFieldsOf (adBuilder .build ()));
@@ -128,5 +141,5 @@ private void runExample(GoogleAdsClient googleAdsClient, long customerId, long a
128141 }
129142 }
130143 }
131- // [END update_expanded_text_ad ]
144+ // [END update_responsive_search_ad ]
132145}
0 commit comments