/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which sitelinks will /// be added.</param> public void Run(AdWordsUser user, long campaignId) { using (CustomerExtensionSettingService customerExtensionSettingService = (CustomerExtensionSettingService)user.GetService(AdWordsService.v201802 .CustomerExtensionSettingService)) { // Create the price extension feed item. PriceFeedItem priceFeedItem = new PriceFeedItem() { priceExtensionType = PriceExtensionType.SERVICES, // Price qualifier is optional. priceQualifier = PriceExtensionPriceQualifier.FROM, trackingUrlTemplate = "http://tracker.example.com/?u={lpurl}", language = "en", campaignTargeting = new FeedItemCampaignTargeting() { TargetingCampaignId = campaignId, }, scheduling = new FeedItemSchedule[] { new FeedItemSchedule() { dayOfWeek = DayOfWeek.SATURDAY, startHour = 10, startMinute = MinuteOfHour.ZERO, endHour = 22, endMinute = MinuteOfHour.ZERO }, new FeedItemSchedule() { dayOfWeek = DayOfWeek.SUNDAY, startHour = 10, startMinute = MinuteOfHour.ZERO, endHour = 18, endMinute = MinuteOfHour.ZERO } } }; // To create a price extension, at least three table rows are needed. List <PriceTableRow> priceTableRows = new List <PriceTableRow>(); string currencyCode = "USD"; priceTableRows.Add(CreatePriceTableRow("Scrubs", "Body Scrub, Salt Scrub", "http://www.example.com/scrubs", "http://m.example.com/scrubs", 60000000, currencyCode, PriceExtensionPriceUnit.PER_HOUR)); priceTableRows.Add(CreatePriceTableRow("Hair Cuts", "Once a month", "http://www.example.com/haircuts", "http://m.example.com/haircuts", 75000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH)); priceTableRows.Add(CreatePriceTableRow("Skin Care Package", "Four times a month", "http://www.example.com/skincarepackage", null, 250000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH)); priceFeedItem.tableRows = priceTableRows.ToArray(); // Create your campaign extension settings. This associates the sitelinks // to your campaign. CustomerExtensionSetting customerExtensionSetting = new CustomerExtensionSetting() { extensionType = FeedType.PRICE, extensionSetting = new ExtensionSetting() { extensions = new ExtensionFeedItem[] { priceFeedItem } } }; CustomerExtensionSettingOperation operation = new CustomerExtensionSettingOperation() { operand = customerExtensionSetting, @operator = Operator.ADD }; try { // Add the extensions. CustomerExtensionSettingReturnValue retVal = customerExtensionSettingService.mutate( new CustomerExtensionSettingOperation[] { operation }); if (retVal.value != null && retVal.value.Length > 0) { CustomerExtensionSetting newExtensionSetting = retVal.value[0]; Console.WriteLine("Extension setting with type '{0}' was added.", newExtensionSetting.extensionType); } else { Console.WriteLine("No extension settings were created."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create extension settings.", e); } } }
public void MergeFrom(ExtensionFeedItem other) { if (other == null) { return; } if (other.ResourceName.Length != 0) { ResourceName = other.ResourceName; } if (other.ExtensionType != 0) { ExtensionType = other.ExtensionType; } if (other.startDateTime_ != null) { if (startDateTime_ == null || other.StartDateTime != "") { StartDateTime = other.StartDateTime; } } if (other.endDateTime_ != null) { if (endDateTime_ == null || other.EndDateTime != "") { EndDateTime = other.EndDateTime; } } adSchedules_.Add(other.adSchedules_); if (other.Device != 0) { Device = other.Device; } if (other.Status != 0) { Status = other.Status; } switch (other.ExtensionCase) { case ExtensionOneofCase.SitelinkFeedItem: if (SitelinkFeedItem == null) { SitelinkFeedItem = new global::Google.Ads.GoogleAds.V1.Common.SitelinkFeedItem(); } SitelinkFeedItem.MergeFrom(other.SitelinkFeedItem); break; case ExtensionOneofCase.StructuredSnippetFeedItem: if (StructuredSnippetFeedItem == null) { StructuredSnippetFeedItem = new global::Google.Ads.GoogleAds.V1.Common.StructuredSnippetFeedItem(); } StructuredSnippetFeedItem.MergeFrom(other.StructuredSnippetFeedItem); break; case ExtensionOneofCase.AppFeedItem: if (AppFeedItem == null) { AppFeedItem = new global::Google.Ads.GoogleAds.V1.Common.AppFeedItem(); } AppFeedItem.MergeFrom(other.AppFeedItem); break; case ExtensionOneofCase.CallFeedItem: if (CallFeedItem == null) { CallFeedItem = new global::Google.Ads.GoogleAds.V1.Common.CallFeedItem(); } CallFeedItem.MergeFrom(other.CallFeedItem); break; case ExtensionOneofCase.CalloutFeedItem: if (CalloutFeedItem == null) { CalloutFeedItem = new global::Google.Ads.GoogleAds.V1.Common.CalloutFeedItem(); } CalloutFeedItem.MergeFrom(other.CalloutFeedItem); break; case ExtensionOneofCase.TextMessageFeedItem: if (TextMessageFeedItem == null) { TextMessageFeedItem = new global::Google.Ads.GoogleAds.V1.Common.TextMessageFeedItem(); } TextMessageFeedItem.MergeFrom(other.TextMessageFeedItem); break; case ExtensionOneofCase.PriceFeedItem: if (PriceFeedItem == null) { PriceFeedItem = new global::Google.Ads.GoogleAds.V1.Common.PriceFeedItem(); } PriceFeedItem.MergeFrom(other.PriceFeedItem); break; case ExtensionOneofCase.PromotionFeedItem: if (PromotionFeedItem == null) { PromotionFeedItem = new global::Google.Ads.GoogleAds.V1.Common.PromotionFeedItem(); } PromotionFeedItem.MergeFrom(other.PromotionFeedItem); break; case ExtensionOneofCase.LocationFeedItem: if (LocationFeedItem == null) { LocationFeedItem = new global::Google.Ads.GoogleAds.V1.Common.LocationFeedItem(); } LocationFeedItem.MergeFrom(other.LocationFeedItem); break; case ExtensionOneofCase.AffiliateLocationFeedItem: if (AffiliateLocationFeedItem == null) { AffiliateLocationFeedItem = new global::Google.Ads.GoogleAds.V1.Common.AffiliateLocationFeedItem(); } AffiliateLocationFeedItem.MergeFrom(other.AffiliateLocationFeedItem); break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
/// <summary> /// Creates an extension feed item for price extension. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="campaignId">ID of the campaign to target.</param> /// <returns>the resource name of the newly created extension feed item.</returns> private string CreateExtensionFeedItem(GoogleAdsClient client, long customerId, long campaignId) { // Get the ExtensionFeedItemServiceClient. ExtensionFeedItemServiceClient extensionFeedItemService = client.GetService(Services.V4.ExtensionFeedItemService); // Creates the price extension feed item. PriceFeedItem priceFeedItem = new PriceFeedItem() { Type = PriceExtensionType.Services, // Optional: sets a qualifier text to show with the price extension. PriceQualifier = PriceExtensionPriceQualifier.From, TrackingUrlTemplate = "http://tracker.example.com/?u={lpurl}", LanguageCode = "en", // To create a price extension, at least three price offerings are needed. PriceOfferings = { CreatePriceOffer( "Scrubs", "Body Scrub, Salt Scrub", 60000000, // 60 USD "USD", PriceExtensionPriceUnit.PerHour, "http://www.example.com/scrubs", "http://m.example.com/scrubs"), CreatePriceOffer( "Hair Cuts", "Once a month", 75000000, // 75 USD "USD", PriceExtensionPriceUnit.PerMonth, "http://www.example.com/haircuts", "http://m.example.com/haircuts"), CreatePriceOffer( "Skin Care Package", "Four times a month", 250000000, // 250 USD "USD", PriceExtensionPriceUnit.PerMonth, "http://www.example.com/skincarepackage", null) } }; // Creates an extension feed item from the price feed item. ExtensionFeedItem extensionFeedItem = new ExtensionFeedItem() { ExtensionType = ExtensionType.Price, PriceFeedItem = priceFeedItem, TargetedCampaign = ResourceNames.Campaign(customerId, campaignId), AdSchedules = { CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Sunday, 10, MinuteOfHour.Zero, 18, MinuteOfHour.Zero), CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Saturday, 10, MinuteOfHour.Zero, 22, MinuteOfHour.Zero) } }; // Creates an operation to add the feed item. ExtensionFeedItemOperation operation = new ExtensionFeedItemOperation() { Create = extensionFeedItem }; // Issues a mutate request to add the extension feed item and prints its information. MutateExtensionFeedItemsResponse response = extensionFeedItemService.MutateExtensionFeedItems(customerId.ToString(), new[] { operation }); string resourceName = response.Results[0].ResourceName; Console.WriteLine($"Created extension feed item with resource name: {resourceName}."); return(resourceName); }
public override int GetHashCode() { int hash = 1; if (ResourceName.Length != 0) { hash ^= ResourceName.GetHashCode(); } if (ExtensionType != 0) { hash ^= ExtensionType.GetHashCode(); } if (startDateTime_ != null) { hash ^= StartDateTime.GetHashCode(); } if (endDateTime_ != null) { hash ^= EndDateTime.GetHashCode(); } hash ^= adSchedules_.GetHashCode(); if (Device != 0) { hash ^= Device.GetHashCode(); } if (Status != 0) { hash ^= Status.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.SitelinkFeedItem) { hash ^= SitelinkFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.StructuredSnippetFeedItem) { hash ^= StructuredSnippetFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.AppFeedItem) { hash ^= AppFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.CallFeedItem) { hash ^= CallFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.CalloutFeedItem) { hash ^= CalloutFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.TextMessageFeedItem) { hash ^= TextMessageFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.PriceFeedItem) { hash ^= PriceFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.PromotionFeedItem) { hash ^= PromotionFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.LocationFeedItem) { hash ^= LocationFeedItem.GetHashCode(); } if (extensionCase_ == ExtensionOneofCase.AffiliateLocationFeedItem) { hash ^= AffiliateLocationFeedItem.GetHashCode(); } hash ^= (int)extensionCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }