/// <summary>Snippet for MutateExtensionFeedItems</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateExtensionFeedItems() { // Create client ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <ExtensionFeedItemOperation> operations = new ExtensionFeedItemOperation[] { new ExtensionFeedItemOperation(), }; // Make the request MutateExtensionFeedItemsResponse response = extensionFeedItemServiceClient.MutateExtensionFeedItems(customerId, operations); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="feedItemId">The feed item ID.</param> /// <param name="geoTargetConstantId">Geo target constant ID to add to the extension /// feed item. Reverts to the United States (2840) if no value passed.</param> // [START AddGeoTarget] public void Run(GoogleAdsClient client, long customerId, long feedItemId, long?geoTargetConstantId) { // Get the ExtensionFeedItemServiceClient. ExtensionFeedItemServiceClient extensionFeedItemServiceClient = client.GetService(Services.V6.ExtensionFeedItemService); // Apply the default geo target constant ID (USA) if none was passed to the function. if (!geoTargetConstantId.HasValue) { geoTargetConstantId = 2840L; } // Creates an extension feed item using the specified feed item ID and geo target // constant ID for targeting. ExtensionFeedItem extensionFeedItem = new ExtensionFeedItem() { ResourceName = ResourceNames.ExtensionFeedItem(customerId, feedItemId), TargetedGeoTargetConstant = ResourceNames.GeoTargetConstant(geoTargetConstantId.Value) }; // Constructs an operation that will update the extension feed item, using the // FieldMasks utility to derive the update mask. This mask tells the Google Ads API // which attributes of the extension feed item you want to change. ExtensionFeedItemOperation operation = new ExtensionFeedItemOperation() { Update = extensionFeedItem, UpdateMask = FieldMasks.AllSetFieldsOf(extensionFeedItem) }; try { // Issues a mutate request to update the extension feed item. MutateExtensionFeedItemsResponse response = extensionFeedItemServiceClient.MutateExtensionFeedItems(customerId.ToString(), new[] { operation }); // Prints the resource name of the updated extension feed item. Console.WriteLine("Updated extension feed item with resource name " + $"{response.Results.First().ResourceName}."); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="feedItemId">The feed item ID to update.</param> /// <param name="sitelinkText">The new sitelink text.</param> // [START UpdateSitelink] public void Run(GoogleAdsClient client, long customerId, long feedItemId, string sitelinkText) { // Get the ExtensionFeedItemService. ExtensionFeedItemServiceClient extensionFeedItemService = client.GetService(Services.V6.ExtensionFeedItemService); // Create an extension feed item using the specified feed item ID and sitelink text. ExtensionFeedItem extensionFeedItem = new ExtensionFeedItem { ResourceName = ResourceNames.ExtensionFeedItem(customerId, feedItemId), SitelinkFeedItem = new SitelinkFeedItem { LinkText = sitelinkText } }; // Construct an operation that will update the extension feed item using the FieldMasks // utilities to derive the update mask. This mask tells the Google Ads API which // attributes of the extension feed item you want to change. ExtensionFeedItemOperation extensionFeedItemOperation = new ExtensionFeedItemOperation { Update = extensionFeedItem, UpdateMask = FieldMasks.AllSetFieldsOf(extensionFeedItem) }; try { // Issue a mutate request to update the extension feed item. MutateExtensionFeedItemsResponse response = extensionFeedItemService.MutateExtensionFeedItems( customerId.ToString(), new[] { extensionFeedItemOperation }); // Print the resource name of the updated extension feed item. Console.WriteLine("Updated extension feed item with resource name " + $"'{response.Results.First().ResourceName}'."); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary>Snippet for MutateExtensionFeedItems</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateExtensionFeedItemsRequestObject() { // Create client ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create(); // Initialize request argument(s) MutateExtensionFeedItemsRequest request = new MutateExtensionFeedItemsRequest { CustomerId = "", Operations = { new ExtensionFeedItemOperation(), }, PartialFailure = false, ValidateOnly = false, }; // Make the request MutateExtensionFeedItemsResponse response = extensionFeedItemServiceClient.MutateExtensionFeedItems(request); }
/// <summary>Snippet for MutateExtensionFeedItems</summary> public void MutateExtensionFeedItemsRequestObject() { // Snippet: MutateExtensionFeedItems(MutateExtensionFeedItemsRequest, CallSettings) // Create client ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create(); // Initialize request argument(s) MutateExtensionFeedItemsRequest request = new MutateExtensionFeedItemsRequest { CustomerId = "", Operations = { new ExtensionFeedItemOperation(), }, PartialFailure = false, ValidateOnly = false, ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified, }; // Make the request MutateExtensionFeedItemsResponse response = extensionFeedItemServiceClient.MutateExtensionFeedItems(request); // End snippet }
/// <summary> /// Creates an image extension. /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The client customer ID.</param> /// <param name="imageAssetId">The ID of the image asset to be used for creating image /// extension.</param> /// <returns>Resource name of the newly created image extension.</returns> private static string CreateImageExtension(GoogleAdsClient client, long customerId, long imageAssetId) { // Get the ExtensionFeedItemServiceClient. ExtensionFeedItemServiceClient extensionFeedItemService = client.GetService(Services.V10.ExtensionFeedItemService); // Creates the image feed item using the provided image. ImageFeedItem imageFeedItem = new ImageFeedItem() { ImageAsset = ResourceNames.Asset(customerId, imageAssetId) }; // Creates an ExtensionFeedItem from the ImageFeedItem. ExtensionFeedItem extensionFeedItem = new ExtensionFeedItem() { ImageFeedItem = imageFeedItem }; ExtensionFeedItemOperation operation = new ExtensionFeedItemOperation() { Create = extensionFeedItem }; // Adds the ExtensionFeedItem. MutateExtensionFeedItemsResponse response = extensionFeedItemService.MutateExtensionFeedItems(customerId.ToString(), new[] { operation }); // Displays the result. string resourceName = response.Results.First().ResourceName; Console.WriteLine($"Created an image extension with resource name '{resourceName}'."); return(resourceName); }
/// <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.V3.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); }
// [END AddSitelinks] /// <summary> /// Creates a list of ExtensionFeedItems. /// </summary> ///<param name="client">The Google Ads API client.</param> ///<param name="customerId">The client customer ID.</param> ///<param name="campaignResourceName">The resource name of the campaign to target.</param> // [START AddSitelinks_1] private static List <string> CreateExtensionFeedItems(GoogleAdsClient client, long customerId, string campaignResourceName) { // Get the ExtensionFeedItemServiceClient. ExtensionFeedItemServiceClient extensionFeedItemService = client.GetService(Services.V6.ExtensionFeedItemService); SitelinkFeedItem sitelinkFeedItem1 = CreateSitelinkFeedItem( "Store Hours", "http://www.example.com/storehours"); // Creates an ExtensionFeedItem from the SitelinkFeedItem. ExtensionFeedItem extensionFeedItem1 = new ExtensionFeedItem() { ExtensionType = ExtensionType.Sitelink, SitelinkFeedItem = sitelinkFeedItem1, TargetedCampaign = campaignResourceName }; List <ExtensionFeedItemOperation> operations = new List <ExtensionFeedItemOperation>(); // Creates an ExtensionFeedItemOperation and adds it to the operations List. operations.Add(new ExtensionFeedItemOperation() { Create = extensionFeedItem1 }); SitelinkFeedItem sitelinkFeedItem2 = CreateSitelinkFeedItem( "Thanksgiving Specials", "http://www.example.com/thanksgiving"); DateTime startTime = new DateTime(DateTime.Now.Year, 11, 20, 0, 0, 0); if (startTime < DateTime.Now) { // Move the startTime to next year if the current date is past November 20th. startTime = startTime.AddYears(1); } // Converts to a string in the required format. string startTimeString = startTime.ToString("yyyy-MM-dd hh:mm:ss"); // Use the same year as startTime when creating endTime. DateTime endTime = new DateTime(startTime.Year, 11, 27, 23, 59, 59); string unitedStates = ResourceNames.GeoTargetConstant(2840); ExtensionFeedItem extensionFeedItem2 = new ExtensionFeedItem() { ExtensionType = ExtensionType.Sitelink, SitelinkFeedItem = sitelinkFeedItem2, TargetedCampaign = campaignResourceName, // StartDateTime should be formatted in "yyyy-MM-dd hh:mm:ss" format. StartDateTime = startTime.ToString("yyyy-MM-dd hh:mm:ss"), // EndDateTime should be formatted in "yyyy-MM-dd hh:mm:ss" format. EndDateTime = endTime.ToString("yyyy-MM-dd hh:mm:ss"), // Targets this sitelink for United States only. // A list of country codes can be referenced here: // https://developers.google.com/adwords/api/docs/appendix/geotargeting TargetedGeoTargetConstant = ResourceNames.GeoTargetConstant(2840) }; operations.Add(new ExtensionFeedItemOperation() { Create = extensionFeedItem2 }); SitelinkFeedItem sitelinkFeedItem3 = CreateSitelinkFeedItem( "Wifi available", "http://www.example.com/mobile/wifi"); ExtensionFeedItem extensionFeedItem3 = new ExtensionFeedItem() { ExtensionType = ExtensionType.Sitelink, SitelinkFeedItem = sitelinkFeedItem3, TargetedCampaign = campaignResourceName, Device = FeedItemTargetDevice.Mobile, TargetedKeyword = new KeywordInfo() { Text = "free wifi", MatchType = KeywordMatchType.Broad } }; operations.Add(new ExtensionFeedItemOperation() { Create = extensionFeedItem3 }); SitelinkFeedItem sitelinkFeedItem4 = CreateSitelinkFeedItem( "Happy hours", "http://www.example.com/happyhours"); ExtensionFeedItem extensionFeedItem4 = new ExtensionFeedItem() { ExtensionType = ExtensionType.Sitelink, SitelinkFeedItem = sitelinkFeedItem4, TargetedCampaign = campaignResourceName, AdSchedules = { CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Monday, 18, MinuteOfHour.Zero, 21, MinuteOfHour.Zero), CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Tuesday, 18, MinuteOfHour.Zero, 21, MinuteOfHour.Zero), CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Wednesday, 18, MinuteOfHour.Zero, 21, MinuteOfHour.Zero), CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Thursday, 18, MinuteOfHour.Zero, 21, MinuteOfHour.Zero), CreateAdScheduleInfo(DayOfWeekEnum.Types.DayOfWeek.Friday, 18, MinuteOfHour.Zero, 21, MinuteOfHour.Zero), } }; operations.Add(new ExtensionFeedItemOperation() { Create = extensionFeedItem4 }); // Adds the ExtensionFeedItem. MutateExtensionFeedItemsResponse response = extensionFeedItemService.MutateExtensionFeedItems(customerId.ToString(), operations); Console.WriteLine($"Added {response.Results.Count}:"); List <string> resourceNames = new List <string>(); foreach (MutateExtensionFeedItemResult result in response.Results) { Console.WriteLine($"Created ExtensionFeedItems with " + $"resource name '{result.ResourceName}'."); resourceNames.Add(result.ResourceName); } return(resourceNames); }