public static string zipCodeToState(this Member member) { string state = String.Empty; // XmlNode node = null; try { //using (WebClient webClient = new WebClient()) //{ // if (!String.IsNullOrEmpty(member.ZipCode)) // { // var requestUrl = "www.webservicex.net/uszip.asmx/GetInfoByZIP?USZip=" + member.ZipCode.Trim(); // var xml = webClient.DownloadString(requestUrl); // var xmlDoc = new XmlDocument(); // xmlDoc.LoadXml(xml); // node = xmlDoc.SelectSingleNode("NewDataSet/Table/State"); // if (node != null) // { // state = node.InnerText; // } // } //} state = GeoTargeting.GetStateByZip(member.ZipCode); }catch (Exception ex) { Sitecore.Diagnostics.Log.Error("Error from Member Extension Method zipCodeToState:\n " + ex.Message, ex); } return(state); }
public void UpdateCampaign() { GeoTargeting currentGeo = new GeoTargeting("512,513"); DateTime startTime = new DateTime(2013, 5, 24, 12, 00, 0, 0); DateTime endTime = new DateTime(2013, 5, 29, 12, 00, 0, 0); campaign = Campaign.Create(5661, 13985, 1, currentGeo, BidTypes.CPC, true, startTime, AdSourceTypes.MobiSage); campaign.EndDate = endTime; campaign.Name = "111"; campaign.Status = AdStatus.Delete; campaign.IsMoreDaysBudget = 1; campaign.MoreDayBudget.Initialize(null); campaign.MoreDayBudget.Initialize("('2012-05-25 00:00:00','66.0000'),('2012-05-26 00:00:00','66.0000'),('2012-05-27 00:00:00','66.0000'),('2012-05-28 00:00:00','66.0000'),('2012-05-29 00:00:00','66.0000')"); campaign.DailyBudget = 5; campaign.AdUrl = "http://iphone.myzaker.com/zaker/ad/adsage.php?u={udid}&t={timestamp}"; campaign.AppleStore = ""; campaignData = ConverterFactory.GetCampaignConverter().ConvertToNetworkObject(campaign); UpdateCampaignByIdProcessor processor = new UpdateCampaignByIdProcessor(); FakedBusinessTransaction transaction = new FakedBusinessTransaction(); transaction.Request = new UpdateCampaignByIdRequestMessage { UserId = 4696, Data = campaignData }; processor.Process(transaction); UpdateCampaignByIdResponseMessage rsqMsg = (UpdateCampaignByIdResponseMessage)transaction.Response; }
public void CreateCampaign() { GeoTargeting currentGeo = new GeoTargeting("512,513"); DateTime startTime = new DateTime(2013, 12, 30, 14, 00, 0, 0); DateTime endTime = new DateTime(2014, 1, 1, 00, 00, 0, 0); campaign = Campaign.Create(5709, 0, 1, currentGeo, BidTypes.CPC, true, startTime, AdSourceTypes.AdHub); campaign.EndDate = endTime; campaign.Name = "7777"; campaign.Status = AdStatus.Launching; campaign.IsMoreDaysBudget = 0; //campaign.MoreDayBudget.Initialize("('2013-06-04','3'),('2013-06-05','3'),('2013-06-06','3')"); campaign.DailyBudget = 5; campaign.AdUrl = "http://iphone.myzaker.com/zaker/ad/adsage.php?u={udid}&t={timestamp}"; campaign.AppleStore = ""; //campaignData = new CampaignData {AccountId = 5661}; campaignData = ConverterFactory.GetCampaignConverter().ConvertToNetworkObject(campaign); CreateNewCampaignProcessor processor = new CreateNewCampaignProcessor(); FakedBusinessTransaction transaction = new FakedBusinessTransaction(); transaction.Request = new CreateNewCampaignRequestMessage { UserId = 4696, Data = campaignData }; processor.Process(transaction); CreateNewCampaignResponseMessage rspMsg = (CreateNewCampaignResponseMessage)transaction.Response; }
private void PopulateContent() { hlBackToHomepage.NavigateUrl = MainsectionItem.GetHomePageItem().GetUrl(); // TODO: find member location? litLocation.Text = GeoTargeting.GetStateByZip(ProfileMember.ZipCode); // Avatar var user = TelligentService.GetUser(ScreenName); if (user != null) { imgAvatar.ImageUrl = user.AvatarUrl; } else { // TODO: fallback image? imgAvatar.Visible = false; } // Hide support from user viewing their own profile if (IsUserLoggedIn && !string.IsNullOrEmpty(CurrentMember.ScreenName) && CurrentMember.ScreenName == ScreenName) { pnlSupport.Visible = false; } else { pnlSupport.Visible = ProfileMember.allowConnections; } // Conditional content for logged in viewers or impersonating visitor if (!IsUserLoggedIn || IsImpersonatingVistor) { if (ProfileMember.allowConnections && ProfileMember.Children.Any()) { rptChildren.DataSource = ProfileMember.Children; rptChildren.DataBind(); } } else { } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService)user.GetService(DfpService.v201511.ProductTemplateService); // Set the ID of the product template. long productTemplateId = long.Parse(_T("INSERT_PRODUCT_TEMPLATE_ID_HERE")); // Create a statement to get the product template. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :id") .OrderBy("id ASC") .Limit(1) .AddValue("id", productTemplateId); try { // Get product templates by statement. ProductTemplatePage page = productTemplateService .getProductTemplatesByStatement(statementBuilder.ToStatement()); ProductTemplate productTemplate = page.results[0]; // Add geo targeting for Canada to the product template. Location countryLocation = new Location(); countryLocation.id = 2124L; Targeting productTemplateTargeting = productTemplate.builtInTargeting; GeoTargeting geoTargeting = productTemplateTargeting.geoTargeting; List <Location> existingTargetedLocations = new List <Location>(); if (geoTargeting == null) { geoTargeting = new GeoTargeting(); } else if (geoTargeting.targetedLocations != null) { existingTargetedLocations = new List <Location>(geoTargeting.targetedLocations); } existingTargetedLocations.Add(countryLocation); Location[] newTargetedLocations = new Location[existingTargetedLocations.Count]; existingTargetedLocations.CopyTo(newTargetedLocations); geoTargeting.targetedLocations = newTargetedLocations; productTemplateTargeting.geoTargeting = geoTargeting; productTemplate.builtInTargeting = productTemplateTargeting; // Update the product template on the server. ProductTemplate[] productTemplates = productTemplateService .updateProductTemplates(new ProductTemplate[] { productTemplate }); if (productTemplates != null) { foreach (ProductTemplate updatedProductTemplate in productTemplates) { Console.WriteLine("A product template with ID = '{0}' and name '{1}' was updated.", updatedProductTemplate.id, updatedProductTemplate.name); } } else { Console.WriteLine("No product templates updated."); } } catch (Exception e) { Console.WriteLine("Failed to update product templates. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService) user.GetService(DfpService.v201508.ProductTemplateService); // Set the ID of the product template. long productTemplateId = long.Parse(_T("INSERT_PRODUCT_TEMPLATE_ID_HERE")); // Create a statement to get the product template. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :id") .OrderBy("id ASC") .Limit(1) .AddValue("id", productTemplateId); try { // Get product templates by statement. ProductTemplatePage page = productTemplateService .getProductTemplatesByStatement(statementBuilder.ToStatement()); ProductTemplate productTemplate = page.results[0]; // Add geo targeting for Canada to the product template. Location countryLocation = new Location(); countryLocation.id = 2124L; Targeting productTemplateTargeting = productTemplate.builtInTargeting; GeoTargeting geoTargeting = productTemplateTargeting.geoTargeting; List<Location> existingTargetedLocations = new List<Location>(); if (geoTargeting == null) { geoTargeting = new GeoTargeting(); } else if (geoTargeting.targetedLocations != null) { existingTargetedLocations = new List<Location>(geoTargeting.targetedLocations); } existingTargetedLocations.Add(countryLocation); Location[] newTargetedLocations = new Location[existingTargetedLocations.Count]; existingTargetedLocations.CopyTo(newTargetedLocations); geoTargeting.targetedLocations = newTargetedLocations; productTemplateTargeting.geoTargeting = geoTargeting; productTemplate.builtInTargeting = productTemplateTargeting; // Update the product template on the server. ProductTemplate[] productTemplates = productTemplateService .updateProductTemplates(new ProductTemplate[] {productTemplate}); if (productTemplates != null) { foreach (ProductTemplate updatedProductTemplate in productTemplates) { Console.WriteLine("A product template with ID = '{0}' and name '{1}' was updated.", updatedProductTemplate.id, updatedProductTemplate.name); } } else { Console.WriteLine("No product templates updated."); } } catch (Exception e) { Console.WriteLine("Failed to update product templates. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code examples. /// </summary> public void Run(DfpUser user) { using (LineItemService lineItemService = (LineItemService)user.GetService(DfpService.v201705.LineItemService)) { // Set the order that all created line items will belong to and the // placement ID to target. long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); long[] targetPlacementIds = new long[] { long.Parse(_T("INSERT_PLACEMENT_ID_HERE")) }; // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); inventoryTargeting.targetedPlacementIds = targetPlacementIds; // Create geographical targeting. GeoTargeting geoTargeting = new GeoTargeting(); // Include the US and Quebec, Canada. Location countryLocation = new Location(); countryLocation.id = 2840L; Location regionLocation = new Location(); regionLocation.id = 20123L; geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; Location postalCodeLocation = new Location(); postalCodeLocation.id = 9000093; // Exclude Chicago and the New York metro area. Location cityLocation = new Location(); cityLocation.id = 1016367L; Location metroLocation = new Location(); metroLocation.id = 200501L; geoTargeting.excludedLocations = new Location[] { cityLocation, metroLocation }; // Exclude domains that are not under the network's control. UserDomainTargeting userDomainTargeting = new UserDomainTargeting(); userDomainTargeting.domains = new String[] { "usa.gov" }; userDomainTargeting.targeted = false; // Create day-part targeting. DayPartTargeting dayPartTargeting = new DayPartTargeting(); dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER; // Target only the weekend in the browser's timezone. DayPart saturdayDayPart = new DayPart(); saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201705.DayOfWeek.SATURDAY; saturdayDayPart.startTime = new TimeOfDay(); saturdayDayPart.startTime.hour = 0; saturdayDayPart.startTime.minute = MinuteOfHour.ZERO; saturdayDayPart.endTime = new TimeOfDay(); saturdayDayPart.endTime.hour = 24; saturdayDayPart.endTime.minute = MinuteOfHour.ZERO; DayPart sundayDayPart = new DayPart(); sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201705.DayOfWeek.SUNDAY; sundayDayPart.startTime = new TimeOfDay(); sundayDayPart.startTime.hour = 0; sundayDayPart.startTime.minute = MinuteOfHour.ZERO; sundayDayPart.endTime = new TimeOfDay(); sundayDayPart.endTime.hour = 24; sundayDayPart.endTime.minute = MinuteOfHour.ZERO; dayPartTargeting.dayParts = new DayPart[] { saturdayDayPart, sundayDayPart }; // Create technology targeting. TechnologyTargeting technologyTargeting = new TechnologyTargeting(); // Create browser targeting. BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.isTargeted = true; // Target just the Chrome browser. Technology browserTechnology = new Technology(); browserTechnology.id = 500072L; browserTargeting.browsers = new Technology[] { browserTechnology }; technologyTargeting.browserTargeting = browserTargeting; // Create an array to store local line item objects. LineItem[] lineItems = new LineItem[5]; for (int i = 0; i < 5; i++) { LineItem lineItem = new LineItem(); lineItem.name = "Line item #" + i; lineItem.orderId = orderId; lineItem.targeting = new Targeting(); lineItem.targeting.inventoryTargeting = inventoryTargeting; lineItem.targeting.geoTargeting = geoTargeting; lineItem.targeting.userDomainTargeting = userDomainTargeting; lineItem.targeting.dayPartTargeting = dayPartTargeting; lineItem.targeting.technologyTargeting = technologyTargeting; lineItem.lineItemType = LineItemType.STANDARD; lineItem.allowOverbook = true; // Set the creative rotation type to even. lineItem.creativeRotationType = CreativeRotationType.EVEN; // Set the size of creatives that can be associated with this line item. Size size = new Size(); size.width = 300; size.height = 250; size.isAspectRatio = false; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; lineItem.creativePlaceholders = new CreativePlaceholder[] { creativePlaceholder }; // Set the line item to run for one month. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York"); // Set the cost per unit to $2. lineItem.costType = CostType.CPM; lineItem.costPerUnit = new Money(); lineItem.costPerUnit.currencyCode = "USD"; lineItem.costPerUnit.microAmount = 2000000L; // Set the number of units bought to 500,000 so that the budget is // $1,000. Goal goal = new Goal(); goal.goalType = GoalType.LIFETIME; goal.unitType = UnitType.IMPRESSIONS; goal.units = 500000L; lineItem.primaryGoal = goal; lineItems[i] = lineItem; } try { // Create the line items on the server. lineItems = lineItemService.createLineItems(lineItems); if (lineItems != null) { foreach (LineItem lineItem in lineItems) { Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and" + " named \"{2}\" was created.", lineItem.id, lineItem.orderId, lineItem.name); } } else { Console.WriteLine("No line items created."); } } catch (Exception e) { Console.WriteLine("Failed to create line items. Exception says \"{0}\"", e.Message); } } }
public void TestCreateLineItems() { // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); inventoryTargeting.targetedPlacementIds = new long[] { placementId }; // Create geographical targeting. GeoTargeting geoTargeting = new GeoTargeting(); // Include the US and Quebec, Canada. Location countryLocation = new Location(); countryLocation.id = 2840L; Location regionLocation = new Location(); regionLocation.id = 20123L; geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; // Exclude Chicago and the New York metro area. Location cityLocation = new Location(); cityLocation.id = 1016367L; Location metroLocation = new Location(); metroLocation.id = 200501L; geoTargeting.excludedLocations = new Location[] { cityLocation, metroLocation }; // Exclude domains that are not under the network's control. UserDomainTargeting userDomainTargeting = new UserDomainTargeting(); userDomainTargeting.domains = new String[] { "usa.gov" }; userDomainTargeting.targeted = false; // Create day-part targeting. DayPartTargeting dayPartTargeting = new DayPartTargeting(); dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER; // Target only the weekend in the browser's timezone. DayPart saturdayDayPart = new DayPart(); saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201602.DayOfWeek.SATURDAY; saturdayDayPart.startTime = new TimeOfDay(); saturdayDayPart.startTime.hour = 0; saturdayDayPart.startTime.minute = MinuteOfHour.ZERO; saturdayDayPart.endTime = new TimeOfDay(); saturdayDayPart.endTime.hour = 24; saturdayDayPart.endTime.minute = MinuteOfHour.ZERO; DayPart sundayDayPart = new DayPart(); sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201602.DayOfWeek.SUNDAY; sundayDayPart.startTime = new TimeOfDay(); sundayDayPart.startTime.hour = 0; sundayDayPart.startTime.minute = MinuteOfHour.ZERO; sundayDayPart.endTime = new TimeOfDay(); sundayDayPart.endTime.hour = 24; sundayDayPart.endTime.minute = MinuteOfHour.ZERO; dayPartTargeting.dayParts = new DayPart[] { saturdayDayPart, sundayDayPart }; // Create technology targeting. TechnologyTargeting technologyTargeting = new TechnologyTargeting(); // Create browser targeting. BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.isTargeted = true; // Target just the Chrome browser. Technology browserTechnology = new Technology(); browserTechnology.id = 500072L; browserTargeting.browsers = new Technology[] { browserTechnology }; technologyTargeting.browserTargeting = browserTargeting; // Create an array to store local line item objects. LineItem[] lineItems = new LineItem[2]; for (int i = 0; i < lineItems.Length; i++) { LineItem lineItem = new LineItem(); lineItem.name = "Line item #" + new TestUtils().GetTimeStamp(); lineItem.orderId = orderId; lineItem.targeting = new Targeting(); lineItem.targeting.inventoryTargeting = inventoryTargeting; lineItem.targeting.geoTargeting = geoTargeting; lineItem.targeting.userDomainTargeting = userDomainTargeting; lineItem.targeting.dayPartTargeting = dayPartTargeting; lineItem.targeting.technologyTargeting = technologyTargeting; lineItem.lineItemType = LineItemType.STANDARD; lineItem.allowOverbook = true; // Set the creative rotation type to even. lineItem.creativeRotationType = CreativeRotationType.EVEN; // Set the size of creatives that can be associated with this line item. Size size = new Size(); size.width = 300; size.height = 250; size.isAspectRatio = false; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; lineItem.creativePlaceholders = new CreativePlaceholder[] { creativePlaceholder }; // Set the line item to run for one month. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York"); // Set the cost per unit to $2. lineItem.costType = CostType.CPM; lineItem.costPerUnit = new Money(); lineItem.costPerUnit.currencyCode = "USD"; lineItem.costPerUnit.microAmount = 2000000L; // Set the number of units bought to 500,000 so that the budget is // $1,000. Goal goal = new Goal(); goal.units = 500000L; goal.unitType = UnitType.IMPRESSIONS; lineItem.primaryGoal = goal; lineItems[i] = lineItem; } LineItem[] localLineItems = null; Assert.DoesNotThrow(delegate() { localLineItems = lineItemService.createLineItems(lineItems); }); Assert.NotNull(localLineItems); Assert.AreEqual(localLineItems.Length, 2); Assert.AreEqual(localLineItems[0].name, lineItems[0].name); Assert.AreEqual(localLineItems[0].orderId, lineItems[0].orderId); Assert.AreEqual(localLineItems[1].name, lineItems[1].name); Assert.AreEqual(localLineItems[1].orderId, lineItems[1].orderId); }
/// <summary> /// Run the code examples. /// </summary> public void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService)user.GetService(DfpService.v201705.ProductTemplateService); // Get the NetworkService. NetworkService networkService = (NetworkService)user.GetService(DfpService.v201705.NetworkService); // Create a product template. ProductTemplate productTemplate = new ProductTemplate(); productTemplate.name = "Product template #" + new Random().Next(int.MaxValue); productTemplate.description = "This product template creates standard proposal line items " + "targeting Chrome browsers with product segmentation on ad units and geo targeting."; // Set the name macro which will be used to generate the names of the products. // This will create a segmentation based on the line item type, ad unit, and location. productTemplate.nameMacro = "<line-item-type> - <ad-unit> - <template-name> - <location>"; // Set the product type so the created proposal line items will be trafficked in DFP. productTemplate.productType = ProductType.DFP; // Set rate type to create CPM priced proposal line items. productTemplate.rateType = RateType.CPM; // Optionally set the creative rotation of the product to serve one or more creatives. productTemplate.roadblockingType = RoadblockingType.ONE_OR_MORE; productTemplate.deliveryRateType = DeliveryRateType.AS_FAST_AS_POSSIBLE; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); creativeMasterPlaceholder.size = new Size() { width = 728, height = 90, isAspectRatio = false }; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder(); companionCreativePlaceholder.size = new Size() { width = 300, height = 250, isAspectRatio = false }; // Set the size of creatives that can be associated with the product template. productTemplate.creativePlaceholders = new CreativePlaceholder[] { creativeMasterPlaceholder, companionCreativePlaceholder }; // Set the type of proposal line item to be created from the product template. productTemplate.lineItemType = LineItemType.STANDARD; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create ad unit targeting for the root ad unit (i.e. the whole network). AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; // Create geo targeting for the US. Location countryLocation = new Location(); countryLocation.id = 2840L; // Create geo targeting for Hong Kong. Location regionLocation = new Location(); regionLocation.id = 2344L; GeoTargeting geoTargeting = new GeoTargeting(); geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; // Add browser targeting to Chrome on the product template distinct from product // segmentation. Browser chromeBrowser = new Browser(); chromeBrowser.id = 500072L; BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.browsers = new Browser[] { chromeBrowser }; TechnologyTargeting technologyTargeting = new TechnologyTargeting(); technologyTargeting.browserTargeting = browserTargeting; Targeting productTemplateTargeting = new Targeting(); productTemplateTargeting.technologyTargeting = technologyTargeting; productTemplate.builtInTargeting = productTemplateTargeting; productTemplate.customizableAttributes = new CustomizableAttributes() { allowPlacementTargetingCustomization = true }; // Add inventory and geo targeting as product segmentation. ProductSegmentation productSegmentation = new ProductSegmentation(); productSegmentation.adUnitSegments = new AdUnitTargeting[] { adUnitTargeting }; productSegmentation.geoSegment = geoTargeting; productTemplate.productSegmentation = productSegmentation; try { // Create the product template on the server. ProductTemplate[] productTemplates = productTemplateService.createProductTemplates( new ProductTemplate[] { productTemplate }); foreach (ProductTemplate createdProductTemplate in productTemplates) { Console.WriteLine("A product template with ID \"{0}\" and name \"{1}\" was created.", createdProductTemplate.id, createdProductTemplate.name); } } catch (Exception e) { Console.WriteLine("Failed to create product templates. Exception says \"{0}\"", e.Message); } }
public LineItem CreateLineItem(DfpUser user, long orderId, string adUnitId) { LineItemService lineItemService = (LineItemService)user.GetService(DfpService.v201306.LineItemService); long placementId = CreatePlacement(user, new string[] { adUnitId }).id; // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); inventoryTargeting.targetedPlacementIds = new long[] { placementId }; // Create geographical targeting. GeoTargeting geoTargeting = new GeoTargeting(); // Include the US and Quebec, Canada. Location countryLocation = new Location(); countryLocation.id = 2840L; Location regionLocation = new Location(); regionLocation.id = 20123L; geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; // Exclude Chicago and the New York metro area. Location cityLocation = new Location(); cityLocation.id = 1016367L; Location metroLocation = new Location(); metroLocation.id = 200501L; geoTargeting.excludedLocations = new Location[] { cityLocation, metroLocation }; // Exclude domains that are not under the network's control. UserDomainTargeting userDomainTargeting = new UserDomainTargeting(); userDomainTargeting.domains = new String[] { "usa.gov" }; userDomainTargeting.targeted = false; // Create day-part targeting. DayPartTargeting dayPartTargeting = new DayPartTargeting(); dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER; // Target only the weekend in the browser's timezone. DayPart saturdayDayPart = new DayPart(); saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201306.DayOfWeek.SATURDAY; saturdayDayPart.startTime = new TimeOfDay(); saturdayDayPart.startTime.hour = 0; saturdayDayPart.startTime.minute = MinuteOfHour.ZERO; saturdayDayPart.endTime = new TimeOfDay(); saturdayDayPart.endTime.hour = 24; saturdayDayPart.endTime.minute = MinuteOfHour.ZERO; DayPart sundayDayPart = new DayPart(); sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201306.DayOfWeek.SUNDAY; sundayDayPart.startTime = new TimeOfDay(); sundayDayPart.startTime.hour = 0; sundayDayPart.startTime.minute = MinuteOfHour.ZERO; sundayDayPart.endTime = new TimeOfDay(); sundayDayPart.endTime.hour = 24; sundayDayPart.endTime.minute = MinuteOfHour.ZERO; dayPartTargeting.dayParts = new DayPart[] { saturdayDayPart, sundayDayPart }; // Create technology targeting. TechnologyTargeting technologyTargeting = new TechnologyTargeting(); // Create browser targeting. BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.isTargeted = true; // Target just the Chrome browser. Technology browserTechnology = new Technology(); browserTechnology.id = 500072L; browserTargeting.browsers = new Technology[] { browserTechnology }; technologyTargeting.browserTargeting = browserTargeting; LineItem lineItem = new LineItem(); lineItem.name = "Line item #" + new TestUtils().GetTimeStamp(); lineItem.orderId = orderId; lineItem.targeting = new Targeting(); lineItem.targeting.inventoryTargeting = inventoryTargeting; lineItem.targeting.geoTargeting = geoTargeting; lineItem.targeting.userDomainTargeting = userDomainTargeting; lineItem.targeting.dayPartTargeting = dayPartTargeting; lineItem.targeting.technologyTargeting = technologyTargeting; lineItem.lineItemType = LineItemType.STANDARD; lineItem.allowOverbook = true; // Set the creative rotation type to even. lineItem.creativeRotationType = CreativeRotationType.EVEN; // Set the size of creatives that can be associated with this line item. Size size = new Size(); size.width = 300; size.height = 250; size.isAspectRatio = false; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; lineItem.creativePlaceholders = new CreativePlaceholder[] { creativePlaceholder }; // Set the length of the line item to run. //lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1)); // Set the cost per unit to $2. lineItem.costType = CostType.CPM; lineItem.costPerUnit = new Money(); lineItem.costPerUnit.currencyCode = "USD"; lineItem.costPerUnit.microAmount = 2000000L; // Set the number of units bought to 500,000 so that the budget is // $1,000. lineItem.unitsBought = 500000L; lineItem.unitType = UnitType.IMPRESSIONS; return(lineItemService.createLineItem(lineItem)); }
/// <summary> /// Run the code examples. /// </summary> public void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService)user.GetService(DfpService.v201708.ProductTemplateService); // Get the NetworkService. NetworkService networkService = (NetworkService)user.GetService(DfpService.v201708.NetworkService); // Create a product template. ProductTemplate productTemplate = new ProductTemplate(); productTemplate.name = "Programmatic product template #" + new Random().Next(int.MaxValue); productTemplate.description = "This product template creates programmatic proposal line " + "items targeting all ad units with product segmentation on geo targeting."; // Set the name macro which will be used to generate the names of the products. // This will create a segmentation based on the line item type, ad unit, and location. productTemplate.nameMacro = "<line-item-type> - <ad-unit> - <template-name> - <location>"; // Set the product type so the created proposal line items will be trafficked in DFP. productTemplate.productType = ProductType.DFP; // Set required Marketplace information. productTemplate.productTemplateMarketplaceInfo = new ProductTemplateMarketplaceInfo() { adExchangeEnvironment = AdExchangeEnvironment.DISPLAY, }; // Set rate type to create CPM priced proposal line items. productTemplate.rateType = RateType.CPM; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = new Size() { width = 300, height = 250, isAspectRatio = false }; // Set the size of creatives that can be associated with the product template. productTemplate.creativePlaceholders = new CreativePlaceholder[] { creativePlaceholder }; // Set the type of proposal line item to be created from the product template. productTemplate.lineItemType = LineItemType.STANDARD; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create ad unit targeting for the root ad unit (i.e. the whole network). AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; // Create geo targeting for the US. Location countryLocation = new Location(); countryLocation.id = 2840L; // Create geo targeting for Hong Kong. Location regionLocation = new Location(); regionLocation.id = 2344L; GeoTargeting geoTargeting = new GeoTargeting(); geoTargeting.targetedLocations = new Location[] { countryLocation, regionLocation }; // Add inventory and geo targeting as product segmentation. ProductSegmentation productSegmentation = new ProductSegmentation(); productSegmentation.adUnitSegments = new AdUnitTargeting[] { adUnitTargeting }; productSegmentation.geoSegment = geoTargeting; productTemplate.productSegmentation = productSegmentation; try { // Create the product template on the server. ProductTemplate[] productTemplates = productTemplateService.createProductTemplates( new ProductTemplate[] { productTemplate }); foreach (ProductTemplate createdProductTemplate in productTemplates) { Console.WriteLine("A programmatic product template with ID \"{0}\" " + "and name \"{1}\" was created.", createdProductTemplate.id, createdProductTemplate.name); } } catch (Exception e) { Console.WriteLine("Failed to create product templates. Exception says \"{0}\"", e.Message); } }
public void TestCreateLineItems() { // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); inventoryTargeting.targetedPlacementIds = new long[] {placementId}; // Create geographical targeting. GeoTargeting geoTargeting = new GeoTargeting(); // Include the US and Quebec, Canada. Location countryLocation = new Location(); countryLocation.id = 2840L; Location regionLocation = new Location(); regionLocation.id = 20123L; geoTargeting.targetedLocations = new Location[] {countryLocation, regionLocation}; // Exclude Chicago and the New York metro area. Location cityLocation = new Location(); cityLocation.id = 1016367L; Location metroLocation = new Location(); metroLocation.id = 200501L; geoTargeting.excludedLocations = new Location[] {cityLocation, metroLocation}; // Exclude domains that are not under the network's control. UserDomainTargeting userDomainTargeting = new UserDomainTargeting(); userDomainTargeting.domains = new String[] {"usa.gov"}; userDomainTargeting.targeted = false; // Create day-part targeting. DayPartTargeting dayPartTargeting = new DayPartTargeting(); dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER; // Target only the weekend in the browser's timezone. DayPart saturdayDayPart = new DayPart(); saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201508.DayOfWeek.SATURDAY; saturdayDayPart.startTime = new TimeOfDay(); saturdayDayPart.startTime.hour = 0; saturdayDayPart.startTime.minute = MinuteOfHour.ZERO; saturdayDayPart.endTime = new TimeOfDay(); saturdayDayPart.endTime.hour = 24; saturdayDayPart.endTime.minute = MinuteOfHour.ZERO; DayPart sundayDayPart = new DayPart(); sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201508.DayOfWeek.SUNDAY; sundayDayPart.startTime = new TimeOfDay(); sundayDayPart.startTime.hour = 0; sundayDayPart.startTime.minute = MinuteOfHour.ZERO; sundayDayPart.endTime = new TimeOfDay(); sundayDayPart.endTime.hour = 24; sundayDayPart.endTime.minute = MinuteOfHour.ZERO; dayPartTargeting.dayParts = new DayPart[] {saturdayDayPart, sundayDayPart}; // Create technology targeting. TechnologyTargeting technologyTargeting = new TechnologyTargeting(); // Create browser targeting. BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.isTargeted = true; // Target just the Chrome browser. Technology browserTechnology = new Technology(); browserTechnology.id = 500072L; browserTargeting.browsers = new Technology[] {browserTechnology}; technologyTargeting.browserTargeting = browserTargeting; // Create an array to store local line item objects. LineItem[] lineItems = new LineItem[2]; for (int i = 0; i < lineItems.Length; i++) { LineItem lineItem = new LineItem(); lineItem.name = "Line item #" + new TestUtils().GetTimeStamp(); lineItem.orderId = orderId; lineItem.targeting = new Targeting(); lineItem.targeting.inventoryTargeting = inventoryTargeting; lineItem.targeting.geoTargeting = geoTargeting; lineItem.targeting.userDomainTargeting = userDomainTargeting; lineItem.targeting.dayPartTargeting = dayPartTargeting; lineItem.targeting.technologyTargeting = technologyTargeting; lineItem.lineItemType = LineItemType.STANDARD; lineItem.allowOverbook = true; // Set the creative rotation type to even. lineItem.creativeRotationType = CreativeRotationType.EVEN; // Set the size of creatives that can be associated with this line item. Size size = new Size(); size.width = 300; size.height = 250; size.isAspectRatio = false; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; lineItem.creativePlaceholders = new CreativePlaceholder[] {creativePlaceholder}; // Set the line item to run for one month. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York"); // Set the cost per unit to $2. lineItem.costType = CostType.CPM; lineItem.costPerUnit = new Money(); lineItem.costPerUnit.currencyCode = "USD"; lineItem.costPerUnit.microAmount = 2000000L; // Set the number of units bought to 500,000 so that the budget is // $1,000. Goal goal = new Goal(); goal.units = 500000L; goal.unitType = UnitType.IMPRESSIONS; lineItem.primaryGoal = goal; lineItems[i] = lineItem; } LineItem[] localLineItems = null; Assert.DoesNotThrow(delegate() { localLineItems = lineItemService.createLineItems(lineItems); }); Assert.NotNull(localLineItems); Assert.AreEqual(localLineItems.Length, 2); Assert.AreEqual(localLineItems[0].name, lineItems[0].name); Assert.AreEqual(localLineItems[0].orderId, lineItems[0].orderId); Assert.AreEqual(localLineItems[1].name, lineItems[1].name); Assert.AreEqual(localLineItems[1].orderId, lineItems[1].orderId); }
/// <summary> /// Run the code examples. /// </summary> /// <param name="user">The DFP user object running the code examples.</param> public override void Run(DfpUser user) { // Get the ProductTemplateService. ProductTemplateService productTemplateService = (ProductTemplateService) user.GetService(DfpService.v201508.ProductTemplateService); // Get the NetworkService. NetworkService networkService = (NetworkService) user.GetService(DfpService.v201508.NetworkService); // Create a product template. ProductTemplate productTemplate = new ProductTemplate(); productTemplate.name = "Product template #" + new Random().Next(int.MaxValue); productTemplate.description = "This product template creates standard proposal line items " + "targeting Chrome browsers with product segmentation on ad units and geo targeting."; // Set the name macro which will be used to generate the names of the products. // This will create a segmentation based on the line item type, ad unit, and location. productTemplate.nameMacro = "<line-item-type> - <ad-unit> - <template-name> - <location>"; // Set the product type so the created proposal line items will be trafficked in DFP. productTemplate.productType = ProductType.DFP; // Set rate type to create CPM priced proposal line items. productTemplate.rateType = RateType.CPM; // Optionally set the creative rotation of the product to serve one or more creatives. productTemplate.roadblockingType = RoadblockingType.ONE_OR_MORE; // Create the master creative placeholder. CreativePlaceholder creativeMasterPlaceholder = new CreativePlaceholder(); creativeMasterPlaceholder.size = new Size() {width = 728, height = 90, isAspectRatio = false}; // Create companion creative placeholders. CreativePlaceholder companionCreativePlaceholder = new CreativePlaceholder(); companionCreativePlaceholder.size = new Size() {width = 300, height = 250, isAspectRatio = false}; // Set the size of creatives that can be associated with the product template. productTemplate.creativePlaceholders = new CreativePlaceholder[] {creativeMasterPlaceholder, companionCreativePlaceholder}; // Set the type of proposal line item to be created from the product template. productTemplate.lineItemType = LineItemType.STANDARD; // Get the root ad unit ID used to target the whole site. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create ad unit targeting for the root ad unit (i.e. the whole network). AdUnitTargeting adUnitTargeting = new AdUnitTargeting(); adUnitTargeting.adUnitId = rootAdUnitId; adUnitTargeting.includeDescendants = true; // Create geo targeting for the US. Location countryLocation = new Location(); countryLocation.id = 2840L; // Create geo targeting for Hong Kong. Location regionLocation = new Location(); regionLocation.id = 2344L; GeoTargeting geoTargeting = new GeoTargeting(); geoTargeting.targetedLocations = new Location[] {countryLocation, regionLocation}; // Add browser targeting to Chrome on the product template distinct from product // segmentation. Browser chromeBrowser = new Browser(); chromeBrowser.id = 500072L; BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.browsers = new Browser[] {chromeBrowser}; TechnologyTargeting technologyTargeting = new TechnologyTargeting(); technologyTargeting.browserTargeting = browserTargeting; Targeting productTemplateTargeting = new Targeting(); productTemplateTargeting.technologyTargeting = technologyTargeting; productTemplate.builtInTargeting = productTemplateTargeting; // Add inventory and geo targeting as product segmentation. ProductSegmentation productSegmentation = new ProductSegmentation(); productSegmentation.adUnitSegments = new AdUnitTargeting[] {adUnitTargeting}; productSegmentation.geoSegment = geoTargeting; productTemplate.productSegmentation = productSegmentation; try { // Create the product template on the server. ProductTemplate[] productTemplates = productTemplateService.createProductTemplates( new ProductTemplate[] {productTemplate}); foreach (ProductTemplate createdProductTemplate in productTemplates) { Console.WriteLine("A product template with ID \"{0}\" and name \"{1}\" was created.", createdProductTemplate.id, createdProductTemplate.name); } } catch (Exception e) { Console.WriteLine("Failed to create product templates. Exception says \"{0}\"", e.Message); } }
public virtual void WriteTo(XElement xE) { XElement xItem = null; if (FeedId != null) { xItem = new XElement(XName.Get("feedId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(FeedId.Value.ToString()); xE.Add(xItem); } if (FeedItemId != null) { xItem = new XElement(XName.Get("feedItemId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(FeedItemId.Value.ToString()); xE.Add(xItem); } if (Status != null) { xItem = new XElement(XName.Get("status", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(Status.Value.ToXmlValue()); xE.Add(xItem); } if (StartTime != null) { xItem = new XElement(XName.Get("startTime", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(StartTime); xE.Add(xItem); } if (EndTime != null) { xItem = new XElement(XName.Get("endTime", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(EndTime); xE.Add(xItem); } if (AttributeValues != null) { foreach (var attributeValuesItem in AttributeValues) { xItem = new XElement(XName.Get("attributeValues", "https://adwords.google.com/api/adwords/cm/v201609")); attributeValuesItem.WriteTo(xItem); xE.Add(xItem); } } if (PolicyData != null) { foreach (var policyDataItem in PolicyData) { xItem = new XElement(XName.Get("policyData", "https://adwords.google.com/api/adwords/cm/v201609")); policyDataItem.WriteTo(xItem); xE.Add(xItem); } } if (DevicePreference != null) { xItem = new XElement(XName.Get("devicePreference", "https://adwords.google.com/api/adwords/cm/v201609")); DevicePreference.WriteTo(xItem); xE.Add(xItem); } if (Scheduling != null) { xItem = new XElement(XName.Get("scheduling", "https://adwords.google.com/api/adwords/cm/v201609")); Scheduling.WriteTo(xItem); xE.Add(xItem); } if (CampaignTargeting != null) { xItem = new XElement(XName.Get("campaignTargeting", "https://adwords.google.com/api/adwords/cm/v201609")); CampaignTargeting.WriteTo(xItem); xE.Add(xItem); } if (AdGroupTargeting != null) { xItem = new XElement(XName.Get("adGroupTargeting", "https://adwords.google.com/api/adwords/cm/v201609")); AdGroupTargeting.WriteTo(xItem); xE.Add(xItem); } if (KeywordTargeting != null) { xItem = new XElement(XName.Get("keywordTargeting", "https://adwords.google.com/api/adwords/cm/v201609")); KeywordTargeting.WriteTo(xItem); xE.Add(xItem); } if (GeoTargeting != null) { xItem = new XElement(XName.Get("geoTargeting", "https://adwords.google.com/api/adwords/cm/v201609")); GeoTargeting.WriteTo(xItem); xE.Add(xItem); } if (GeoTargetingRestriction != null) { xItem = new XElement(XName.Get("geoTargetingRestriction", "https://adwords.google.com/api/adwords/cm/v201609")); GeoTargetingRestriction.WriteTo(xItem); xE.Add(xItem); } if (UrlCustomParameters != null) { xItem = new XElement(XName.Get("urlCustomParameters", "https://adwords.google.com/api/adwords/cm/v201609")); UrlCustomParameters.WriteTo(xItem); xE.Add(xItem); } }
/// <summary> /// Run the code examples. /// </summary> /// <param name="user">The DFP user object running the code examples.</param> public override void Run(DfpUser user) { // Get the LineItemService. LineItemService lineItemService = (LineItemService) user.GetService(DfpService.v201511.LineItemService); // Set the order that all created line items will belong to and the // placement ID to target. long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); long[] targetPlacementIds = new long[] {long.Parse(_T("INSERT_PLACEMENT_ID_HERE"))}; // Create inventory targeting. InventoryTargeting inventoryTargeting = new InventoryTargeting(); inventoryTargeting.targetedPlacementIds = targetPlacementIds; // Create geographical targeting. GeoTargeting geoTargeting = new GeoTargeting(); // Include the US and Quebec, Canada. Location countryLocation = new Location(); countryLocation.id = 2840L; Location regionLocation = new Location(); regionLocation.id = 20123L; geoTargeting.targetedLocations = new Location[] {countryLocation, regionLocation}; Location postalCodeLocation = new Location(); postalCodeLocation.id = 9000093; // Exclude Chicago and the New York metro area. Location cityLocation = new Location(); cityLocation.id = 1016367L; Location metroLocation = new Location(); metroLocation.id = 200501L; geoTargeting.excludedLocations = new Location[] {cityLocation, metroLocation}; // Exclude domains that are not under the network's control. UserDomainTargeting userDomainTargeting = new UserDomainTargeting(); userDomainTargeting.domains = new String[] {"usa.gov"}; userDomainTargeting.targeted = false; // Create day-part targeting. DayPartTargeting dayPartTargeting = new DayPartTargeting(); dayPartTargeting.timeZone = DeliveryTimeZone.BROWSER; // Target only the weekend in the browser's timezone. DayPart saturdayDayPart = new DayPart(); saturdayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201511.DayOfWeek.SATURDAY; saturdayDayPart.startTime = new TimeOfDay(); saturdayDayPart.startTime.hour = 0; saturdayDayPart.startTime.minute = MinuteOfHour.ZERO; saturdayDayPart.endTime = new TimeOfDay(); saturdayDayPart.endTime.hour = 24; saturdayDayPart.endTime.minute = MinuteOfHour.ZERO; DayPart sundayDayPart = new DayPart(); sundayDayPart.dayOfWeek = Google.Api.Ads.Dfp.v201511.DayOfWeek.SUNDAY; sundayDayPart.startTime = new TimeOfDay(); sundayDayPart.startTime.hour = 0; sundayDayPart.startTime.minute = MinuteOfHour.ZERO; sundayDayPart.endTime = new TimeOfDay(); sundayDayPart.endTime.hour = 24; sundayDayPart.endTime.minute = MinuteOfHour.ZERO; dayPartTargeting.dayParts = new DayPart[] {saturdayDayPart, sundayDayPart}; // Create technology targeting. TechnologyTargeting technologyTargeting = new TechnologyTargeting(); // Create browser targeting. BrowserTargeting browserTargeting = new BrowserTargeting(); browserTargeting.isTargeted = true; // Target just the Chrome browser. Technology browserTechnology = new Technology(); browserTechnology.id = 500072L; browserTargeting.browsers = new Technology[] {browserTechnology}; technologyTargeting.browserTargeting = browserTargeting; // Create an array to store local line item objects. LineItem[] lineItems = new LineItem[5]; for (int i = 0; i < 5; i++) { LineItem lineItem = new LineItem(); lineItem.name = "Line item #" + i; lineItem.orderId = orderId; lineItem.targeting = new Targeting(); lineItem.targeting.inventoryTargeting = inventoryTargeting; lineItem.targeting.geoTargeting = geoTargeting; lineItem.targeting.userDomainTargeting = userDomainTargeting; lineItem.targeting.dayPartTargeting = dayPartTargeting; lineItem.targeting.technologyTargeting = technologyTargeting; lineItem.lineItemType = LineItemType.STANDARD; lineItem.allowOverbook = true; // Set the creative rotation type to even. lineItem.creativeRotationType = CreativeRotationType.EVEN; // Set the size of creatives that can be associated with this line item. Size size = new Size(); size.width = 300; size.height = 250; size.isAspectRatio = false; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; lineItem.creativePlaceholders = new CreativePlaceholder[] {creativePlaceholder}; // Set the line item to run for one month. lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York"); // Set the cost per unit to $2. lineItem.costType = CostType.CPM; lineItem.costPerUnit = new Money(); lineItem.costPerUnit.currencyCode = "USD"; lineItem.costPerUnit.microAmount = 2000000L; // Set the number of units bought to 500,000 so that the budget is // $1,000. Goal goal = new Goal(); goal.goalType = GoalType.LIFETIME; goal.unitType = UnitType.IMPRESSIONS; goal.units = 500000L; lineItem.primaryGoal = goal; lineItems[i] = lineItem; } try { // Create the line items on the server. lineItems = lineItemService.createLineItems(lineItems); if (lineItems != null) { foreach (LineItem lineItem in lineItems) { Console.WriteLine("A line item with ID \"{0}\", belonging to order ID \"{1}\", and" + " named \"{2}\" was created.", lineItem.id, lineItem.orderId, lineItem.name); } } else { Console.WriteLine("No line items created."); } } catch (Exception e) { Console.WriteLine("Failed to create line items. Exception says \"{0}\"", e.Message); } }