/// <summary> /// Run the example. /// </summary> /// <param name="parsedArgs">Parsed arguments for the example.</param> protected override void Run(Dictionary <string, object> parsedArgs) { string accountId = (string)parsedArgs["account_id"]; long? pretargetingConfigId = (long?)parsedArgs["pretargeting_config_id"]; string pretargetingConfigName = $"bidders/{accountId}/pretargetingConfigs/{pretargetingConfigId}"; RemoveTargetedPublishersRequest body = new RemoveTargetedPublishersRequest(); body.PublisherIds = (IList <string>)parsedArgs["publisher_ids"]; BiddersResource.PretargetingConfigsResource.RemoveTargetedPublishersRequest request = rtbService.Bidders.PretargetingConfigs.RemoveTargetedPublishers( body, pretargetingConfigName); PretargetingConfig response = null; Console.WriteLine("Removing publisher IDs from publisher targeting for pretargeting " + "configuration with name: {0}", pretargetingConfigName); try { response = request.Execute(); } catch (System.Exception exception) { throw new ApplicationException( $"Real-time Bidding API returned error response:\n{exception.Message}"); } Utilities.PrintPretargetingConfiguration(response); }
/// <summary> /// Run the example. /// </summary> /// <param name="parsedArgs">Parsed arguments for the example.</param> protected override void Run(Dictionary <string, object> parsedArgs) { string accountId = (string)parsedArgs["account_id"]; long? pretargetingConfigId = (long?)parsedArgs["pretargeting_config_id"]; string pretargetingConfigName = $"bidders/{accountId}/pretargetingConfigs/{pretargetingConfigId}"; AddTargetedAppsRequest body = new AddTargetedAppsRequest(); body.TargetingMode = (string)parsedArgs["mobile_app_targeting_mode"]; body.AppIds = (IList <string>)parsedArgs["mobile_app_targeting_app_ids"]; BiddersResource.PretargetingConfigsResource.AddTargetedAppsRequest request = rtbService.Bidders.PretargetingConfigs.AddTargetedApps(body, pretargetingConfigName); PretargetingConfig response = null; Console.WriteLine("Updating mobile app targeting with new app IDs for pretargeting " + "configuration with name: {0}", pretargetingConfigName); try { response = request.Execute(); } catch (System.Exception exception) { throw new ApplicationException( $"Real-time Bidding API returned error response:\n{exception.Message}"); } Utilities.PrintPretargetingConfiguration(response); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="service">An authenticated AdExchangeBuyerService</param> public override void Run(AdExchangeBuyerService service) { long accountId = long.Parse("INSERT ACCOUNT ID HERE"); string configName = "INSERT CONFIG NAME HERE"; PretargetingConfig.DimensionsData dimensions = new PretargetingConfig.DimensionsData { Width = int.Parse("INSERT WIDTH HERE"), Height = int.Parse("INSERT HEIGHT HERE") }; bool active = bool.Parse("INSERT TRUE OR FALSE HERE"); PretargetingConfig config = new PretargetingConfig { ConfigName = configName, CreativeType = new[] { "PRETARGETING_CREATIVE_TYPE_HTML" }, Dimensions = new[] { dimensions }, IsActive = active }; PretargetingConfig responseConfig = service.PretargetingConfig. Insert(config, accountId).Execute(); Console.WriteLine("Inserted new pretargeting config:"); Console.WriteLine("Config Name: {0}", responseConfig.ConfigName); Console.WriteLine("Config Id: {0}", responseConfig.ConfigId); Console.WriteLine("Is active: {0}", responseConfig.IsActive); Console.WriteLine("Creative Type: {0}", responseConfig.CreativeType); }
/// <summary> /// Run the example. /// </summary> /// <param name="parsedArgs">Parsed arguments for the example.</param> protected override void Run(Dictionary <string, object> parsedArgs) { string accountId = (string)parsedArgs["account_id"]; long? pretargetingConfigId = (long?)parsedArgs["pretargeting_config_id"]; string name = $"bidders/{accountId}/pretargetingConfigs/{pretargetingConfigId}"; BiddersResource.PretargetingConfigsResource.ActivateRequest request = rtbService.Bidders.PretargetingConfigs.Activate( new ActivatePretargetingConfigRequest(), name); PretargetingConfig response = null; Console.WriteLine("Activating pretargeting configuration with name: '{0}'", name); try { response = request.Execute(); } catch (System.Exception exception) { throw new ApplicationException( $"Real-time Bidding API returned error response:\n{exception.Message}"); } Utilities.PrintPretargetingConfiguration(response); }
/// <summary> /// Run the example. /// </summary> /// <param name="parsedArgs">Parsed arguments for the example.</param> protected override void Run(Dictionary <string, object> parsedArgs) { string accountId = (string)parsedArgs["account_id"]; long? pretargetingConfigId = (long?)parsedArgs["pretargeting_config_id"]; string name = $"bidders/{accountId}/pretargetingConfigs/{pretargetingConfigId}"; NumericTargetingDimension geoTargeting = new NumericTargetingDimension(); geoTargeting.IncludedIds = new List <long?>() { 200635L, // Austin, TX 1014448L, // Boulder, CO 1022183L, // Hoboken, NJ 200622L, // New Orleans, LA 1023191L, // New York, NY 9061237L, // Mountain View, CA 1014221L // San Francisco, CA }; CreativeDimensions dimensions1 = new CreativeDimensions(); dimensions1.Height = 480L; dimensions1.Width = 320L; CreativeDimensions dimensions2 = new CreativeDimensions(); dimensions2.Height = 1080L; dimensions2.Width = 1920L; List <CreativeDimensions> creativeDimensions = new List <CreativeDimensions>() { dimensions1, dimensions2 }; PretargetingConfig body = new PretargetingConfig(); body.DisplayName = (string)parsedArgs["display_name"]; // Note that repeated fields such as this are completely overwritten by the contents // included in the patch request. body.IncludedFormats = new List <string>() { "HTML", "VAST" }; body.GeoTargeting = geoTargeting; body.IncludedCreativeDimensions = creativeDimensions; BiddersResource.PretargetingConfigsResource.PatchRequest request = rtbService.Bidders.PretargetingConfigs.Patch(body, name); PretargetingConfig response = null; Console.WriteLine("Patching pretargeting configuration with name: {0}", name); try { response = request.Execute(); } catch (System.Exception exception) { throw new ApplicationException( $"Real-time Bidding API returned error response:\n{exception.Message}"); } Utilities.PrintPretargetingConfiguration(response); }
/// <summary> /// Run the example. /// </summary> /// <param name="parsedArgs">Parsed arguments for the example.</param> protected override void Run(Dictionary <string, object> parsedArgs) { string accountId = (string)parsedArgs["account_id"]; string parent = $"bidders/{accountId}"; NumericTargetingDimension geoTargeting = new NumericTargetingDimension(); geoTargeting.IncludedIds = (IList <long?>)parsedArgs["included_geo_ids"]; geoTargeting.ExcludedIds = (IList <long?>)parsedArgs["excluded_geo_ids"]; NumericTargetingDimension userListTargeting = new NumericTargetingDimension(); userListTargeting.IncludedIds = (IList <long?>)parsedArgs["included_user_list_ids"]; userListTargeting.ExcludedIds = (IList <long?>)parsedArgs["excluded_user_list_ids"]; NumericTargetingDimension verticalTargeting = new NumericTargetingDimension(); verticalTargeting.IncludedIds = (IList <long?>)parsedArgs["included_vertical_ids"]; verticalTargeting.ExcludedIds = (IList <long?>)parsedArgs["excluded_vertical_ids"]; CreativeDimensions dimensions = new CreativeDimensions(); dimensions.Height = (long?)parsedArgs["included_creative_dimension_height"]; dimensions.Width = (long?)parsedArgs["included_creative_dimension_width"]; StringTargetingDimension webTargeting = new StringTargetingDimension(); webTargeting.TargetingMode = (string)parsedArgs["web_targeting_mode"]; webTargeting.Values = (IList <string>)parsedArgs["web_targeting_urls"]; StringTargetingDimension mobileAppTargeting = new StringTargetingDimension(); mobileAppTargeting.TargetingMode = (string)parsedArgs["mobile_app_targeting_mode"]; mobileAppTargeting.Values = (IList <string>)parsedArgs["mobile_app_targeting_app_ids"]; NumericTargetingDimension mobileAppCategoryTargeting = new NumericTargetingDimension(); mobileAppCategoryTargeting.IncludedIds = (IList <long?>)parsedArgs[ "included_mobile_app_targeting_category_ids"]; mobileAppCategoryTargeting.ExcludedIds = (IList <long?>)parsedArgs[ "excluded_mobile_app_targeting_category_ids"]; AppTargeting appTargeting = new AppTargeting(); appTargeting.MobileAppTargeting = mobileAppTargeting; appTargeting.MobileAppCategoryTargeting = mobileAppCategoryTargeting; StringTargetingDimension publisherTargeting = new StringTargetingDimension(); publisherTargeting.TargetingMode = (string)parsedArgs["publisher_targeting_mode"]; publisherTargeting.Values = (IList <string>)parsedArgs["publisher_ids"]; PretargetingConfig newConfig = new PretargetingConfig(); newConfig.DisplayName = (string)parsedArgs["display_name"]; newConfig.IncludedFormats = (IList <string>)parsedArgs["included_formats"]; newConfig.GeoTargeting = geoTargeting; newConfig.UserListTargeting = userListTargeting; newConfig.InterstitialTargeting = (string)parsedArgs["interstitial_targeting"]; newConfig.AllowedUserTargetingModes = (IList <string>)parsedArgs[ "allowed_user_targeting_modes"]; newConfig.ExcludedContentLabelIds = (IList <long?>)parsedArgs[ "excluded_content_label_ids"]; newConfig.IncludedUserIdTypes = (IList <string>)parsedArgs["included_user_id_types"]; newConfig.IncludedLanguages = (IList <string>)parsedArgs["included_language_codes"]; newConfig.IncludedMobileOperatingSystemIds = (IList <long?>)parsedArgs[ "included_mobile_os_ids"]; newConfig.VerticalTargeting = verticalTargeting; newConfig.IncludedPlatforms = (IList <string>)parsedArgs["included_platforms"]; newConfig.IncludedCreativeDimensions = new List <CreativeDimensions> { dimensions }; newConfig.IncludedEnvironments = (IList <string>)parsedArgs["included_environments"]; newConfig.WebTargeting = webTargeting; newConfig.AppTargeting = appTargeting; newConfig.PublisherTargeting = publisherTargeting; newConfig.MinimumViewabilityDecile = (int?)parsedArgs["minimum_viewability_decile"]; BiddersResource.PretargetingConfigsResource.CreateRequest request = rtbService.Bidders.PretargetingConfigs.Create(newConfig, parent); PretargetingConfig response = null; Console.WriteLine("Creating pretargeting configuration for bidder: {0}", parent); try { response = request.Execute(); } catch (System.Exception exception) { throw new ApplicationException( $"Real-time Bidding API returned error response:\n{exception.Message}"); } Utilities.PrintPretargetingConfiguration(response); }
/// <summary> /// Updates an existing pretargeting config. /// Documentation https://developers.google.com/adexchangebuyer/v1.3/reference/pretargetingConfig/update /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Adexchangebuyer service.</param> /// <param name="accountId">The account id to update the pretargeting config for.</param> /// <param name="configId">The specific id of the configuration to update.</param> /// <param name="body">A valid Adexchangebuyer v1.3 body.</param> /// <returns>PretargetingConfigResponse</returns> public static PretargetingConfig Update(AdexchangebuyerService service, string accountId, string configId, PretargetingConfig body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (accountId == null) { throw new ArgumentNullException(accountId); } if (configId == null) { throw new ArgumentNullException(configId); } // Make the request. return(service.PretargetingConfig.Update(body, accountId, configId).Execute()); } catch (Exception ex) { throw new Exception("Request PretargetingConfig.Update failed.", ex); } }
/// <summary> /// Print a human-readable representation of a single pretargeting configuration. /// </summary> public static void PrintPretargetingConfiguration(PretargetingConfig configuration) { Console.WriteLine("* Pretargeting configuration name: {0}", configuration.Name); Console.WriteLine("\t- Display name: {0}", configuration.DisplayName); Console.WriteLine("\t- Billing ID: {0}", configuration.BillingId); Console.WriteLine("\t- State: {0}", configuration.State); long?maximumQps = configuration.MaximumQps; if (maximumQps != null) { Console.WriteLine("\t- Maximum QPS: {0}", maximumQps); } string interstitialTargeting = configuration.InterstitialTargeting; if (interstitialTargeting != null) { Console.WriteLine("\t- Interstitial targeting: {0}", interstitialTargeting); } int?minimumViewabilityDecile = configuration.MinimumViewabilityDecile; if (minimumViewabilityDecile != null) { Console.WriteLine("\t- Minimum viewability decile: {0}", minimumViewabilityDecile); } IList <string> includedFormats = configuration.IncludedFormats; if (includedFormats != null) { Console.WriteLine("\t- Included formats:\n\t\t" + String.Join("\n\t\t", includedFormats)); } NumericTargetingDimension geoTargeting = configuration.GeoTargeting; if (geoTargeting != null) { IList <long?> includedIds = geoTargeting.IncludedIds; if (includedIds != null) { Console.WriteLine("\t- Included geo IDs:\n\t\t" + String.Join("\n\t\t", includedIds)); } IList <long?> excludedIds = geoTargeting.ExcludedIds; if (excludedIds != null) { Console.WriteLine("\t- Excluded geo IDs:\n\t\t" + String.Join("\n\t\t", excludedIds)); } } IList <long?> invalidGeoIDs = configuration.InvalidGeoIds; if (invalidGeoIDs != null) { Console.WriteLine("\t- Invalid Geo IDs:\n\t\t" + String.Join("\n\t\t", invalidGeoIDs)); } NumericTargetingDimension userListTargeting = configuration.UserListTargeting; if (userListTargeting != null) { IList <long?> includedIds = userListTargeting.IncludedIds; if (includedIds != null) { Console.WriteLine("\t- Included user list IDs:\n\t\t" + String.Join("\n\t\t", includedIds)); } IList <long?> excludedIds = userListTargeting.ExcludedIds; if (excludedIds != null) { Console.WriteLine("\t- Excluded user list IDs:\n\t\t" + String.Join("\n\t\t", excludedIds)); } } IList <string> allowedUserTargetingModes = configuration.AllowedUserTargetingModes; if (allowedUserTargetingModes != null) { Console.WriteLine("\t- Allowed user targeting modes:\n\t\t" + String.Join("\n\t\t", allowedUserTargetingModes)); } IList <long?> excludedContentLabelIds = configuration.ExcludedContentLabelIds; if (excludedContentLabelIds != null) { Console.WriteLine("\t- Excluded content label IDs:\n\t\t" + String.Join("\n\t\t", excludedContentLabelIds)); } IList <string> includedUserIdTypes = configuration.IncludedUserIdTypes; if (includedUserIdTypes != null) { Console.WriteLine("\t- Included user ID types:\n\t\t" + String.Join("\n\t\t", includedUserIdTypes)); } IList <string> includedLanguages = configuration.IncludedLanguages; if (includedLanguages != null) { Console.WriteLine("\t- Included laguages:\n\t\t" + String.Join("\n\t\t", includedLanguages)); } IList <long?> includedMobileOsIds = configuration.IncludedMobileOperatingSystemIds; if (includedMobileOsIds != null) { Console.WriteLine("\t- Included mobile operating system IDs:\n\t\t" + String.Join("\n\t\t", includedMobileOsIds)); } NumericTargetingDimension verticalTargeting = configuration.VerticalTargeting; if (verticalTargeting != null) { IList <long?> includedIds = verticalTargeting.IncludedIds; if (includedIds != null) { Console.WriteLine("\t- Included vertical IDs:\n\t\t" + String.Join("\n\t\t", includedIds)); } IList <long?> excludedIds = verticalTargeting.ExcludedIds; if (excludedIds != null) { Console.WriteLine("\t- Excluded vertical IDs:\n\t\t" + String.Join("\n\t\t", excludedIds)); } } IList <string> includedPlatforms = configuration.IncludedPlatforms; if (includedPlatforms != null) { Console.WriteLine("\t- Included platforms:\n\t\t" + String.Join("\n\t\t", includedPlatforms)); } IList <CreativeDimensions> creativeDimensions = configuration.IncludedCreativeDimensions; if (creativeDimensions != null && creativeDimensions.Count > 0) { Console.WriteLine("\t- Included creative dimensions:"); foreach (CreativeDimensions creativeDimension in creativeDimensions) { Console.WriteLine("\t\tHeight: {0}; Width: {1}", creativeDimension.Height, creativeDimension.Width); } } IList <string> includedEnvironments = configuration.IncludedEnvironments; if (includedEnvironments != null) { Console.WriteLine("\t- Included environments:\n\t\t" + String.Join("\n\t\t", includedEnvironments)); } StringTargetingDimension webTargeting = configuration.WebTargeting; if (webTargeting != null) { Console.WriteLine("\t- Web targeting:"); Console.WriteLine("\t\t- Targeting mode: {0}", webTargeting.TargetingMode); Console.WriteLine("\t\t- Site URLs:\n\t\t\t" + String.Join("\n\t\t\t", webTargeting.Values)); } AppTargeting appTargeting = configuration.AppTargeting; if (appTargeting != null) { Console.WriteLine("\t- App targeting:"); StringTargetingDimension mobileAppTargeting = appTargeting.MobileAppTargeting; if (mobileAppTargeting != null) { Console.WriteLine("\t\t- Mobile app targeting:"); Console.WriteLine("\t\t\t- Targeting mode: {0}", mobileAppTargeting.TargetingMode); Console.WriteLine("\t\t\t- Mobile app IDs:\n\t\t\t\t" + String.Join("\n\t\t\t\t", mobileAppTargeting.Values)); } NumericTargetingDimension mobileAppCategoryTargeting = appTargeting.MobileAppCategoryTargeting; if (mobileAppCategoryTargeting != null) { Console.WriteLine("\t\t- Mobile app category targeting:"); IList <long?> includedIds = mobileAppCategoryTargeting.IncludedIds; if (includedIds != null) { Console.WriteLine("\t\t\t- Included mobile app category targeting IDs:" + "\n\t\t\t\t" + String.Join("\n\t\t\t\t", includedIds)); } IList <long?> excludedIds = mobileAppCategoryTargeting.ExcludedIds; if (excludedIds != null) { Console.WriteLine("\t\t\t- Excluded mobile app category targeting IDs:" + "\n\t\t\t\t" + String.Join("\n\t\t\t\t", excludedIds)); } } } StringTargetingDimension publisherTargeting = configuration.PublisherTargeting; if (publisherTargeting != null) { Console.WriteLine("\t- Publisher targeting:"); Console.WriteLine("\t\t- Targeting mode: {0}", publisherTargeting.TargetingMode); Console.WriteLine("\t\t- Publisher IDs:\n\t\t\t" + String.Join("\n\t\t\t", publisherTargeting.Values)); } }