/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string targetingTemplateName = _T("INSERT_TARGETING_TEMPLATE_NAME_HERE"); // Create the targeting template. TargetingTemplate template = new TargetingTemplate(); template.AdvertiserId = advertiserId; template.Name = targetingTemplateName; // Configure the template to serve ads on Monday, Wednesday, and Friday from 9-10am // and 3-5pm. DayPartTargeting dayTargeting = new DayPartTargeting(); dayTargeting.DaysOfWeek = new List <string>() { "MONDAY", "WEDNESDAY", "FRIDAY" }; dayTargeting.HoursOfDay = new List <int?>() { 9, 15, 16 }; dayTargeting.UserLocalTime = true; template.DayPartTargeting = dayTargeting; // Insert the targeting template. TargetingTemplate result = service.TargetingTemplates.Insert(template, profileId).Execute(); // Display the new targeting template ID. Console.WriteLine("Targeting template with ID {0} was created.", result.Id); }
/// <summary> /// Inserts a new targeting template. /// Documentation https://developers.google.com/dfareporting/v2.7/reference/targetingTemplates/insert /// 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 dfareporting service.</param> /// <param name="profileId">User profile ID associated with this request.</param> /// <param name="body">A valid dfareporting v2.7 body.</param> /// <returns>TargetingTemplateResponse</returns> public static TargetingTemplate Insert(dfareportingService service, string profileId, TargetingTemplate body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (profileId == null) { throw new ArgumentNullException(profileId); } // Make the request. return(service.TargetingTemplates.Insert(body, profileId).Execute()); } catch (Exception ex) { throw new Exception("Request TargetingTemplates.Insert failed.", ex); } }