private void createAppAd( GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) { // Set up video AdVideoAsset adVideoAsset = AdVideoAsset.newBuilder().setAsset("").build(); AppAdInfo appAdInfo = AppAdInfo.newBuilder() .addAllHeadlines( ImmutableList.of( AdTextAsset.newBuilder().setText("test").build(), AdTextAsset.newBuilder().setText("test").build())) .addAllDescriptions( ImmutableList.of( AdTextAsset.newBuilder().setText("test").build(), AdTextAsset.newBuilder().setText("test").build())) .addYoutubeVideos() .build(); Ad ad = Ad.newBuilder().setAppAd(appAdInfo).build(); AdGroupAd adGroupAd = AdGroupAd.newBuilder() .setStatus(AdGroupAdStatusEnum.AdGroupAdStatus.ENABLED) .setAdGroup(adGroupResourceName) .setAd(ad) .build(); AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build(); try (AdGroupAdServiceClient adGroupAdServiceClient = googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) { MutateAdGroupAdsResponse response = adGroupAdServiceClient.mutateAdGroupAds( Long.toString(customerId), ImmutableList.of(operation)); log.info("Created an ad group ad with ad with resource name '%s'%n", response.getResults(0).getResourceName()); } }
When I checked the document, I didn’t find the interface to upload or get the material from youtube and filled the result into the assert field in AdVideoAsset.
AdVideoAsset adVideoAsset = AdVideoAsset.newBuilder().setAsset("").build();
Looking forward to your answer
Advertisement
Answer
I have solved this problem by looking at official documents.
Here is my test code
- Create a YouTube video asset and return the asset ID
// Create a YouTube video asset and return the asset ID,eg:customers/xxxxxxxxxxx/assets/17064058414 public String createYoutubeVideoAssert(Long customerId, String youtubeVideoId) throws IOException { GoogleAdsClient googleAdsClient = googleAdsClientRegister.getClient(); YoutubeVideoAsset youtubeVideoAsset = YoutubeVideoAsset.newBuilder() .setYoutubeVideoId(youtubeVideoId) .build(); Asset asset = Asset.newBuilder() .setName("Jupiter Trip # " + "1234") .setType(AssetTypeEnum.AssetType.YOUTUBE_VIDEO) .setYoutubeVideoAsset(youtubeVideoAsset) .build(); AssetOperation operation = AssetOperation.newBuilder().setCreate(asset).build(); try (AssetServiceClient assetServiceClient = googleAdsClient.getVersion7().createAssetServiceClient()) { MutateAssetsResponse response = assetServiceClient.mutateAssets(Long.toString(customerId), ImmutableList.of(operation)); System.out.printf( "The youtube video asset with resource name '%s' was created.%n", response.getResults(0).getResourceName()); return response.getResults(0).getResourceName(); } }
- create ad group ad
AdVideoAsset adVideoAsset = AdVideoAsset.newBuilder() .setAsset("customers/xxxxxxxxxxx/assets/17064058414") .build();
In the process of docking with Google ads, we have encountered many problems. If we are interested, we can communicate