// [END add_asset_set] // [START add_asset_set_asset] /// <summary> /// Adds an Asset to an AssetSet by creating an AssetSetAsset link. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="assetResourceName">Name of the asset resource.</param> /// <param name="assetSetResourceName">Name of the asset set resource.</param> private void AddAssetsToAssetSet(GoogleAdsClient client, long customerId, string assetResourceName, string assetSetResourceName) { AssetSetAssetServiceClient assetSetAssetService = client.GetService( Services.V10.AssetSetAssetService); AssetSetAsset assetSetAsset = new AssetSetAsset() { Asset = assetResourceName, AssetSet = assetSetResourceName }; // Creates an operation to add the link. AssetSetAssetOperation operation = new AssetSetAssetOperation() { Create = assetSetAsset }; // Sends the mutate request. // Note this is the point that the API will enforce uniqueness of the // DynamicEducationAsset.program_id field. You can have any number of // assets with the same program_id, however, only one Asset is allowed // per AssetSet with the same program ID. MutateAssetSetAssetsResponse response = assetSetAssetService.MutateAssetSetAssets( customerId.ToString(), new[] { operation }); // Prints some information about the response. string resourceName = response.Results[0].ResourceName; Console.WriteLine($"Created AssetSetAsset link with resource name {resourceName}."); }
// [END add_asset_set] // [START add_asset_set_asset] /// <summary> /// Adds an Asset to an AssetSet by creating an AssetSetAsset link. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="assetResourceNames">The asset resource names.</param> /// <param name="assetSetResourceName">Resource name of the asset set.</param> private void AddAssetsToAssetSet(GoogleAdsClient client, long customerId, List <string> assetResourceNames, string assetSetResourceName) { AssetSetAssetServiceClient assetSetAssetService = client.GetService( Services.V10.AssetSetAssetService); List <AssetSetAssetOperation> operations = new List <AssetSetAssetOperation>(); foreach (string assetResourceName in assetResourceNames) { AssetSetAsset assetSetAsset = new AssetSetAsset() { Asset = assetResourceName, AssetSet = assetSetResourceName }; // Creates an operation to add the link. AssetSetAssetOperation operation = new AssetSetAssetOperation() { Create = assetSetAsset }; operations.Add(operation); } // Sends the mutate request. MutateAssetSetAssetsResponse response = assetSetAssetService.MutateAssetSetAssets(customerId.ToString(), operations); // Prints some information about the response. string resourceName = response.Results[0].ResourceName; Console.WriteLine($"Created AssetSetAsset link with resource name {resourceName}."); }