/// <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 = $"buyers/{accountId}"; Image nativeImage = new Image(); nativeImage.Url = (string)parsedArgs["native_image_url"]; nativeImage.Height = (int?)parsedArgs["native_image_height"]; nativeImage.Width = (int?)parsedArgs["native_image_width"]; Image nativeLogo = new Image(); nativeLogo.Url = (string)parsedArgs["native_logo_url"]; nativeLogo.Height = (int?)parsedArgs["native_logo_height"]; nativeLogo.Width = (int?)parsedArgs["native_logo_width"]; NativeContent nativeContent = new NativeContent(); nativeContent.Headline = (string)parsedArgs["native_headline"]; nativeContent.Body = (string)parsedArgs["native_body"]; nativeContent.CallToAction = (string)parsedArgs["native_call_to_action"]; nativeContent.AdvertiserName = (string)parsedArgs["native_advertiser_name"]; nativeContent.Image = nativeImage; nativeContent.Logo = nativeLogo; nativeContent.ClickLinkUrl = (string)parsedArgs["native_click_link_url"]; nativeContent.ClickTrackingUrl = (string)parsedArgs["native_click_tracking_url"]; Creative newCreative = new Creative(); newCreative.AdvertiserName = (string)parsedArgs["advertiser_name"]; newCreative.CreativeId = (string)parsedArgs["creative_id"]; newCreative.DeclaredAttributes = (IList <string>)parsedArgs["declared_attributes"]; newCreative.DeclaredClickThroughUrls = (IList <string>)parsedArgs[ "declared_click_urls"]; newCreative.DeclaredRestrictedCategories = (IList <string>)parsedArgs[ "declared_restricted_categories"]; newCreative.DeclaredVendorIds = (IList <int?>)parsedArgs["declared_vendor_ids"]; newCreative.Native = nativeContent; BuyersResource.CreativesResource.CreateRequest request = rtbService.Buyers.Creatives.Create(newCreative, parent); Creative response = null; Console.WriteLine("Creating native creative for buyer: {0}", parent); try { response = request.Execute(); } catch (System.Exception exception) { throw new ApplicationException( $"Real-time Bidding API returned error response:\n{exception.Message}"); } Utilities.PrintCreative(response); }
/// <summary> /// Print a human-readable representation of a single creative. /// </summary> public static void PrintCreative(Creative creative) { Console.WriteLine("* Creative ID: {0}", creative.CreativeId); int?version = creative.Version; if (version != null) { Console.WriteLine("\t- Version: {0}", version); } string advertiserName = creative.AdvertiserName; if (advertiserName != null) { Console.WriteLine("\t- Advertiser name: {0}", advertiserName); } string creativeFormat = creative.CreativeFormat; if (creativeFormat != null) { Console.WriteLine("\t- Creative format: {0}", creativeFormat); } CreativeServingDecision servingDecision = creative.CreativeServingDecision; if (servingDecision != null) { Console.WriteLine("\t- Creative serving decision"); Console.WriteLine("\t\tDeals policy compliance: {0}", servingDecision.DealsPolicyCompliance.Status); Console.WriteLine("\t\tNetwork policy compliance: {0}", servingDecision.NetworkPolicyCompliance.Status); Console.WriteLine("\t\tPlatform policy compliance: {0}", servingDecision.PlatformPolicyCompliance.Status); Console.WriteLine("\t\tChina policy compliance: {0}", servingDecision.ChinaPolicyCompliance.Status); Console.WriteLine("\t\tRussia policy compliance: {0}", servingDecision.RussiaPolicyCompliance.Status); } IList <string> declaredClickThroughUrls = creative.DeclaredClickThroughUrls; if (declaredClickThroughUrls != null) { Console.WriteLine("\t- Declared click-through URLs:\n\t\t" + String.Join("\n\t\t", declaredClickThroughUrls)); } IList <string> declaredAttributes = creative.DeclaredAttributes; if (declaredAttributes != null) { Console.WriteLine("\t- Declared attributes:\n\t\t" + String.Join("\n\t\t", declaredAttributes)); } IList <int?> declaredVendorIds = creative.DeclaredVendorIds; if (declaredVendorIds != null) { Console.WriteLine("\t- Declared vendor IDs:\n\t\t" + String.Join("\n\t\t", declaredVendorIds)); } IList <string> declaredRestrictedCategories = creative.DeclaredRestrictedCategories; if (declaredRestrictedCategories != null) { Console.WriteLine("\t- Declared restricted categories:\n\t\t" + String.Join("\n\t\t", declaredRestrictedCategories)); } HtmlContent html = creative.Html; if (html != null) { Console.WriteLine("\t- HTML creative contents:"); Console.WriteLine("\t\tSnippet: {0}", html.Snippet); Console.WriteLine("\t\tHeight: {0}", html.Height); Console.WriteLine("\t\tWidth: {0}", html.Width); } NativeContent native = creative.Native; if (native != null) { Console.WriteLine("\t- Native creative contents:"); Console.WriteLine("\t\tHeadline: {0}", native.Headline); Console.WriteLine("\t\tBody: {0}", native.Body); Console.WriteLine("\t\tCall to action: {0}", native.CallToAction); Console.WriteLine("\t\tAdvertiser name: {0}", native.AdvertiserName); Console.WriteLine("\t\tStar rating: {0}", native.StarRating); Console.WriteLine("\t\tClick link URL: {0}", native.ClickLinkUrl); Console.WriteLine("\t\tClick tracking URL: {0}", native.ClickTrackingUrl); Console.WriteLine("\t\tPrice display text: {0}", native.PriceDisplayText); Image image = native.Image; if (image != null) { Console.WriteLine("\t\tImage contents:"); Console.WriteLine("\t\t\tURL: {0}", image.Url); Console.WriteLine("\t\t\tHeight: {0}", image.Height); Console.WriteLine("\t\t\tWidth: {0}", image.Width); } Image logo = native.Logo; if (logo != null) { Console.WriteLine("\t\tLogo contents:"); Console.WriteLine("\t\t\tURL: {0}", logo.Url); Console.WriteLine("\t\t\tHeight: {0}", logo.Height); Console.WriteLine("\t\t\tWidth: {0}", logo.Width); } Image appIcon = native.AppIcon; if (appIcon != null) { Console.WriteLine("\t\tAppIcon contents:"); Console.WriteLine("\t\t\tURL: {0}", appIcon.Url); Console.WriteLine("\t\t\tHeight: {0}", appIcon.Height); Console.WriteLine("\t\t\tWidth: {0}", appIcon.Width); } } VideoContent video = creative.Video; if (video != null) { Console.WriteLine("\tVideo creative contents:"); string videoUrl = video.VideoUrl; if (videoUrl != null) { Console.WriteLine("\t\tVideo URL: {0}", videoUrl); } string videoVastXml = video.VideoVastXml; if (videoVastXml != null) { Console.WriteLine("\t\tVideo VAST XML:\n{0}", videoVastXml); } } }