googleads / googleads-dotnet-lib

Google Ad Manager SOAP API .NET client library
Apache License 2.0
108 stars 199 forks source link

Adding YouTube Video to MultiAssetResponsiveDisplayAd #220

Closed digitalgym closed 5 years ago

digitalgym commented 5 years ago

Are there any examples of how to provide an existing Youtube video as an asset when creating a Multi-Asset Ad? The below throws an error "operations[0].operand.ad.youtubeVideos[0].asset.assetId"

youTubeVideos = new AssetLink[] { new AssetLink { asset = new Google.Api.Ads.AdWords.v201809.YouTubeVideoAsset { youTubeVideoId = "youtubeVideoID" } } }

Could an example be added here? https://github.com/googleads/googleads-dotnet-lib/blob/master/examples/AdWords/CSharp/v201809/AdvancedOperations/AddMultiAssetResponsiveDisplayAd.cs

digitalgym commented 5 years ago

Found the solution, you need to ADD the asset then use both the assetId and the youTubeVideoId from the url. Would be good to have this added to the examples.

youTubeVideos = new AssetLink[] { new AssetLink { asset = new Google.Api.Ads.AdWords.v201809.YouTubeVideoAsset { youTubeVideoId = "youtubeVideoID" assetId = "assetId"} } }
private long UploadYouTubeAsset(string url)
        {
            using (AssetService assetService =
                (AssetService)user.GetService(AdWordsService.v201809.AssetService))
            {
                YouTubeVideoAsset imageAsset = new YouTubeVideoAsset
                {
                    youTubeVideoId = url
                };
                // Create the image asset.

                // Create the operation.
                AssetOperation operation = new AssetOperation()
                {
                    @operator = Operator.ADD,
                    operand = imageAsset
                };

                // Create the asset and return the ID.
                return assetService.mutate(new AssetOperation[]
                {
                    operation
                }).value[0].assetId;
            }
        }