Example #1
0
 /// <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);
 }
Example #2
0
        /// <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;
            }
        }
Example #3
0
        /// <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 MutateExtensionFeedItemsAsync</summary>
        public async Task MutateExtensionFeedItemsAsync()
        {
            // Snippet: MutateExtensionFeedItemsAsync(string, IEnumerable<ExtensionFeedItemOperation>, CallSettings)
            // Additional: MutateExtensionFeedItemsAsync(string, IEnumerable<ExtensionFeedItemOperation>, CancellationToken)
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <ExtensionFeedItemOperation> operations = new ExtensionFeedItemOperation[]
            {
                new ExtensionFeedItemOperation(),
            };
            // Make the request
            MutateExtensionFeedItemsResponse response = await extensionFeedItemServiceClient.MutateExtensionFeedItemsAsync(customerId, operations);

            // 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);
        }
Example #6
0
        /// <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);
        }