/// <summary>Snippet for GetExtensionFeedItem</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetExtensionFeedItemResourceNames()
 {
     // Create client
     ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create();
     // Initialize request argument(s)
     ExtensionFeedItemName resourceName = ExtensionFeedItemName.FromCustomerFeedItem("[CUSTOMER_ID]", "[FEED_ITEM_ID]");
     // Make the request
     ExtensionFeedItem response = extensionFeedItemServiceClient.GetExtensionFeedItem(resourceName);
 }
 /// <summary>Snippet for GetExtensionFeedItem</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetExtensionFeedItem()
 {
     // Create client
     ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/extensionFeedItems/[FEED_ITEM_ID]";
     // Make the request
     ExtensionFeedItem response = extensionFeedItemServiceClient.GetExtensionFeedItem(resourceName);
 }
Пример #3
0
        /// <summary>Snippet for GetExtensionFeedItemAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetExtensionFeedItemAsync()
        {
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/extensionFeedItems/[EXTENSION_FEED_ITEM]";
            // Make the request
            ExtensionFeedItem response = await extensionFeedItemServiceClient.GetExtensionFeedItemAsync(resourceName);
        }
        /// <summary>Snippet for GetExtensionFeedItemAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetExtensionFeedItemResourceNamesAsync()
        {
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            ExtensionFeedItemName resourceName = ExtensionFeedItemName.FromCustomerExtensionFeedItem("[CUSTOMER]", "[EXTENSION_FEED_ITEM]");
            // Make the request
            ExtensionFeedItem response = await extensionFeedItemServiceClient.GetExtensionFeedItemAsync(resourceName);
        }
Пример #5
0
 /// <summary>Snippet for GetExtensionFeedItem</summary>
 public void GetExtensionFeedItemResourceNames()
 {
     // Snippet: GetExtensionFeedItem(ExtensionFeedItemName, CallSettings)
     // Create client
     ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create();
     // Initialize request argument(s)
     ExtensionFeedItemName resourceName = ExtensionFeedItemName.FromCustomerExtensionFeedItem("[CUSTOMER]", "[EXTENSION_FEED_ITEM]");
     // Make the request
     ExtensionFeedItem response = extensionFeedItemServiceClient.GetExtensionFeedItem(resourceName);
     // End snippet
 }
Пример #6
0
 /// <summary>Snippet for GetExtensionFeedItem</summary>
 public void GetExtensionFeedItem()
 {
     // Snippet: GetExtensionFeedItem(string, CallSettings)
     // Create client
     ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/extensionFeedItems/[EXTENSION_FEED_ITEM]";
     // Make the request
     ExtensionFeedItem response = extensionFeedItemServiceClient.GetExtensionFeedItem(resourceName);
     // End snippet
 }
Пример #7
0
 /// <summary>Snippet for GetExtensionFeedItem</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetExtensionFeedItemRequestObject()
 {
     // Create client
     ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create();
     // Initialize request argument(s)
     GetExtensionFeedItemRequest request = new GetExtensionFeedItemRequest
     {
         ResourceNameAsExtensionFeedItemName = ExtensionFeedItemName.FromCustomerExtensionFeedItem("[CUSTOMER]", "[EXTENSION_FEED_ITEM]"),
     };
     // Make the request
     ExtensionFeedItem response = extensionFeedItemServiceClient.GetExtensionFeedItem(request);
 }
Пример #8
0
        /// <summary>Snippet for GetExtensionFeedItemAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetExtensionFeedItemRequestObjectAsync()
        {
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetExtensionFeedItemRequest request = new GetExtensionFeedItemRequest
            {
                ResourceNameAsExtensionFeedItemName = ExtensionFeedItemName.FromCustomerFeedItem("[CUSTOMER_ID]", "[FEED_ITEM_ID]"),
            };
            // Make the request
            ExtensionFeedItem response = await extensionFeedItemServiceClient.GetExtensionFeedItemAsync(request);
        }
        /// <summary>Snippet for GetExtensionFeedItemAsync</summary>
        public async Task GetExtensionFeedItemResourceNamesAsync()
        {
            // Snippet: GetExtensionFeedItemAsync(ExtensionFeedItemName, CallSettings)
            // Additional: GetExtensionFeedItemAsync(ExtensionFeedItemName, CancellationToken)
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            ExtensionFeedItemName resourceName = ExtensionFeedItemName.FromCustomerFeedItem("[CUSTOMER_ID]", "[FEED_ITEM_ID]");
            // Make the request
            ExtensionFeedItem response = await extensionFeedItemServiceClient.GetExtensionFeedItemAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetExtensionFeedItemAsync</summary>
        public async Task GetExtensionFeedItemAsync()
        {
            // Snippet: GetExtensionFeedItemAsync(string, CallSettings)
            // Additional: GetExtensionFeedItemAsync(string, CancellationToken)
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/extensionFeedItems/[FEED_ITEM_ID]";
            // Make the request
            ExtensionFeedItem response = await extensionFeedItemServiceClient.GetExtensionFeedItemAsync(resourceName);

            // End snippet
        }
Пример #11
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="feedItemId">ID of the extension feed item to migrate.</param>
        public void Run(GoogleAdsClient client, long customerId, long feedItemId)
        {
            // Get the GoogleAdsService client.
            GoogleAdsServiceClient googleAdsServiceClient =
                client.GetService(Services.V10.GoogleAdsService);

            string extensionFeedItemResourceName =
                ResourceNames.ExtensionFeedItem(customerId, feedItemId);

            try
            {
                // Get the target extension feed item.
                ExtensionFeedItem extensionFeedItem =
                    GetExtensionFeedItem(googleAdsServiceClient, customerId, feedItemId);

                // Get all campaign IDs associated with the extension feed item.
                List <long> campaignIds = GetTargetedCampaignIds(googleAdsServiceClient, customerId,
                                                                 extensionFeedItemResourceName);

                // Get all ad group IDs associated with the extension feed item.
                List <long> adGroupIds = GetTargetedAdGroupIds(googleAdsServiceClient, customerId,
                                                               extensionFeedItemResourceName);

                // Create a new Promotion asset that matches the target extension feed item.
                string promotionAssetResourceName = CreatePromotionAssetFromFeed(client,
                                                                                 customerId, extensionFeedItem);

                // Associate the new Promotion asset with the same campaigns as the original.
                AssociateAssetWithCampaigns(client, customerId, promotionAssetResourceName,
                                            campaignIds);

                // Associate the new Promotion asset with the same ad groups as the original.
                AssociateAssetWithAdGroups(client, customerId, promotionAssetResourceName,
                                           adGroupIds);
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                throw;
            }
        }
Пример #12
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;
            }
        }
 /// <summary>Snippet for GetExtensionFeedItem</summary>
 public void GetExtensionFeedItemRequestObject()
 {
     // Snippet: GetExtensionFeedItem(GetExtensionFeedItemRequest, CallSettings)
     // Create client
     ExtensionFeedItemServiceClient extensionFeedItemServiceClient = ExtensionFeedItemServiceClient.Create();
     // Initialize request argument(s)
     GetExtensionFeedItemRequest request = new GetExtensionFeedItemRequest
     {
         ResourceNameAsExtensionFeedItemName = ExtensionFeedItemName.FromCustomerFeedItem("[CUSTOMER_ID]", "[FEED_ITEM_ID]"),
     };
     // Make the request
     ExtensionFeedItem response = extensionFeedItemServiceClient.GetExtensionFeedItem(request);
     // End snippet
 }
Пример #14
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;
            }
        }
Пример #15
0
        /// <summary>Snippet for GetExtensionFeedItemAsync</summary>
        public async Task GetExtensionFeedItemRequestObjectAsync()
        {
            // Snippet: GetExtensionFeedItemAsync(GetExtensionFeedItemRequest, CallSettings)
            // Additional: GetExtensionFeedItemAsync(GetExtensionFeedItemRequest, CancellationToken)
            // Create client
            ExtensionFeedItemServiceClient extensionFeedItemServiceClient = await ExtensionFeedItemServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetExtensionFeedItemRequest request = new GetExtensionFeedItemRequest
            {
                ResourceNameAsExtensionFeedItemName = ExtensionFeedItemName.FromCustomerExtensionFeedItem("[CUSTOMER]", "[EXTENSION_FEED_ITEM]"),
            };
            // Make the request
            ExtensionFeedItem response = await extensionFeedItemServiceClient.GetExtensionFeedItemAsync(request);

            // End snippet
        }
Пример #16
0
        /// <summary>
        /// Updates Site Link Extension at Campaign Level
        /// </summary>
        /// <param name="user">Adwords User Object</param>
        /// <param name="sitelinkFeedItem">SiteLinkFeedItem containing Values to be update</param>
        /// <param name="campaignId">Campaign ID</param>
        /// <returns>Campaign Extension Setting Object with Updated Values</returns>
        public CampaignExtensionSetting UpdateSiteLinkAtCampaignLevel(AdWordsUser user, SitelinkFeedItem sitelinkFeedItem, long campaignId)
        {
            CampaignExtensionSettingService campaignExtensionSettingService = (CampaignExtensionSettingService)user.GetService(AdWordsService.v201809.CampaignExtensionSettingService);

            ExtensionFeedItem[] extensionFeedItems = new ExtensionFeedItem[] { sitelinkFeedItem };

            ExtensionSetting extensionSetting = new ExtensionSetting();

            extensionSetting.extensions = extensionFeedItems;

            CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();

            campaignExtensionSetting.campaignId       = campaignId;
            campaignExtensionSetting.extensionType    = FeedType.SITELINK;
            campaignExtensionSetting.extensionSetting = extensionSetting;

            CampaignExtensionSettingOperation campaignExtensionSettingOperation = new CampaignExtensionSettingOperation();

            campaignExtensionSettingOperation.operand   = campaignExtensionSetting;
            campaignExtensionSettingOperation.@operator = Operator.SET;

            try
            {
                // Add the extensions.
                CampaignExtensionSettingReturnValue campaignExtensionSettingReturnValue = campaignExtensionSettingService.mutate(new [] { campaignExtensionSettingOperation });
                if (campaignExtensionSettingReturnValue.value != null && campaignExtensionSettingReturnValue.value.Length > 0)
                {
                    CampaignExtensionSetting modifiedExtensionItem = campaignExtensionSettingReturnValue.value[0];
                    Logger.Log(Logger.LogType.INFO, "Modification Successful for Feed(ID): " + sitelinkFeedItem.feedId + " with FeedItem(ID): " + sitelinkFeedItem.feedItemId);
                    return(modifiedExtensionItem);
                }
                else
                {
                    Logger.Log(Logger.LogType.WARNING, "Nothing Modified for Feed(ID): " + sitelinkFeedItem.feedId + " with FeedItem(ID): " + sitelinkFeedItem.feedItemId);
                    return(null);
                }
            }
            catch (AdWordsApiException ex)
            {
                Logger.Log(Logger.LogType.EXCEPTION, Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException);
                return(null);
            }
        }
Пример #17
0
        public void GetExtensionFeedItem2()
        {
            Mock <ExtensionFeedItemService.ExtensionFeedItemServiceClient> mockGrpcClient = new Mock <ExtensionFeedItemService.ExtensionFeedItemServiceClient>(MockBehavior.Strict);
            GetExtensionFeedItemRequest request = new GetExtensionFeedItemRequest
            {
                ResourceName = new ExtensionFeedItemName("[CUSTOMER]", "[EXTENSION_FEED_ITEM]").ToString(),
            };
            ExtensionFeedItem expectedResponse = new ExtensionFeedItem
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetExtensionFeedItem(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ExtensionFeedItemServiceClient client = new ExtensionFeedItemServiceClientImpl(mockGrpcClient.Object, null);
            ExtensionFeedItem response            = client.GetExtensionFeedItem(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #18
0
        public async Task GetExtensionFeedItemAsync()
        {
            Mock <ExtensionFeedItemService.ExtensionFeedItemServiceClient> mockGrpcClient = new Mock <ExtensionFeedItemService.ExtensionFeedItemServiceClient>(MockBehavior.Strict);
            GetExtensionFeedItemRequest expectedRequest = new GetExtensionFeedItemRequest
            {
                ResourceName = new ExtensionFeedItemName("[CUSTOMER]", "[EXTENSION_FEED_ITEM]").ToString(),
            };
            ExtensionFeedItem expectedResponse = new ExtensionFeedItem
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetExtensionFeedItemAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <ExtensionFeedItem>(Task.FromResult(expectedResponse), null, null, null, null));
            ExtensionFeedItemServiceClient client   = new ExtensionFeedItemServiceClientImpl(mockGrpcClient.Object, null);
            string            formattedResourceName = new ExtensionFeedItemName("[CUSTOMER]", "[EXTENSION_FEED_ITEM]").ToString();
            ExtensionFeedItem response = await client.GetExtensionFeedItemAsync(formattedResourceName);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <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);
        }
Пример #20
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);
        }
Пример #21
0
        // [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);
        }
Пример #22
0
        /// <summary>
        /// Gets the requested Promotion-type extension feed item.
        ///
        /// Note that extension feed items pertain to feeds that were created by Google. Use
        /// FeedService to instead retrieve a user-created Feed.
        /// </summary>
        /// <param name="googleAdsServiceClient">An initialized Google Ads API Service
        /// client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="feedItemId">ID of the extension feed item to migrate.</param>
        /// <returns>The requested ExtensionFeedItem, or null if no matching item was
        /// found.</returns>
        private ExtensionFeedItem GetExtensionFeedItem(
            GoogleAdsServiceClient googleAdsServiceClient,
            long customerId, long feedItemId)
        {
            // Create a query that will retrieve the requested Promotion-type extension feed item
            // and ensure that all fields are populated.
            string extensionFeedItemQuery = $@"
                SELECT
                    extension_feed_item.id,
                    extension_feed_item.ad_schedules,
                    extension_feed_item.device,
                    extension_feed_item.status,
                    extension_feed_item.start_date_time,
                    extension_feed_item.end_date_time,
                    extension_feed_item.targeted_campaign,
                    extension_feed_item.targeted_ad_group,
                    extension_feed_item.promotion_feed_item.discount_modifier,
                    extension_feed_item.promotion_feed_item.final_mobile_urls,
                    extension_feed_item.promotion_feed_item.final_url_suffix,
                    extension_feed_item.promotion_feed_item.final_urls,
                    extension_feed_item.promotion_feed_item.language_code,
                    extension_feed_item.promotion_feed_item.money_amount_off.amount_micros,
                    extension_feed_item.promotion_feed_item.money_amount_off.currency_code,
                    extension_feed_item.promotion_feed_item.occasion,
                    extension_feed_item.promotion_feed_item.orders_over_amount.amount_micros,
                    extension_feed_item.promotion_feed_item.orders_over_amount.currency_code,
                    extension_feed_item.promotion_feed_item.percent_off,
                    extension_feed_item.promotion_feed_item.promotion_code,
                    extension_feed_item.promotion_feed_item.promotion_end_date,
                    extension_feed_item.promotion_feed_item.promotion_start_date,
                    extension_feed_item.promotion_feed_item.promotion_target,
                    extension_feed_item.promotion_feed_item.tracking_url_template
                FROM extension_feed_item
                WHERE
                    extension_feed_item.extension_type = 'PROMOTION'
                    AND extension_feed_item.id = {feedItemId}
                LIMIT 1";

            ExtensionFeedItem fetchedExtensionFeedItem = null;

            // Issue a search request to get the extension feed item contents.
            googleAdsServiceClient.SearchStream(customerId.ToString(), extensionFeedItemQuery,
                                                delegate(SearchGoogleAdsStreamResponse response)
            {
                fetchedExtensionFeedItem = response.Results.First().ExtensionFeedItem;
            }
                                                );
            Console.WriteLine(
                $"Retrieved details for ad extension with ID {fetchedExtensionFeedItem.Id}.");

            // Create a query to retrieve any URL customer parameters attached to the feed item.
            string urlCustomParametersQuery = $@"
                SELECT feed_item.url_custom_parameters
                FROM feed_item
                WHERE feed_item.id = {feedItemId}";

            // Issue a search request to get any URL custom parameters.
            googleAdsServiceClient.SearchStream(customerId.ToString(), urlCustomParametersQuery,
                                                delegate(SearchGoogleAdsStreamResponse response)
            {
                RepeatedField <CustomParameter> urlCustomParameters =
                    response.Results.First().FeedItem.UrlCustomParameters;
                Console.WriteLine(
                    $"Retrieved {urlCustomParameters.Count} attached URL custom parameters.");
                if (urlCustomParameters.Count > 0)
                {
                    fetchedExtensionFeedItem.PromotionFeedItem.UrlCustomParameters.Add(
                        urlCustomParameters);
                }
            }
                                                );

            return(fetchedExtensionFeedItem);
        }
Пример #23
0
        /// <summary>
        /// Create a Promotion asset that copies values from the specified extension feed item.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="extensionFeedItem">The extension feed item to be migrated.</param>
        /// <returns>The resource name of the newly created Promotion asset.</returns>
        // [START migrate_promotion_feed_to_asset]
        private string CreatePromotionAssetFromFeed(GoogleAdsClient client, long customerId,
                                                    ExtensionFeedItem extensionFeedItem)
        {
            // Get the Asset Service client.
            AssetServiceClient assetServiceClient = client.GetService(Services.V10.AssetService);

            PromotionFeedItem promotionFeedItem = extensionFeedItem.PromotionFeedItem;

            // Create the Promotion asset.
            Asset asset = new Asset
            {
                // Name field is optional.
                Name           = $"Migrated from feed item #{extensionFeedItem.Id}",
                PromotionAsset = new PromotionAsset
                {
                    PromotionTarget     = promotionFeedItem.PromotionTarget,
                    DiscountModifier    = promotionFeedItem.DiscountModifier,
                    RedemptionStartDate = promotionFeedItem.PromotionStartDate,
                    RedemptionEndDate   = promotionFeedItem.PromotionEndDate,
                    Occasion            = promotionFeedItem.Occasion,
                    LanguageCode        = promotionFeedItem.LanguageCode,
                },
                TrackingUrlTemplate = promotionFeedItem.TrackingUrlTemplate,
                FinalUrlSuffix      = promotionFeedItem.FinalUrlSuffix
            };

            // Either PercentOff or MoneyAmountOff must be set.
            if (promotionFeedItem.PercentOff > 0)
            {
                // Adjust the percent off scale when copying.
                asset.PromotionAsset.PercentOff = promotionFeedItem.PercentOff / 100;
            }
            else
            {
                asset.PromotionAsset.MoneyAmountOff = new Money
                {
                    AmountMicros = promotionFeedItem.MoneyAmountOff.AmountMicros,
                    CurrencyCode = promotionFeedItem.MoneyAmountOff.CurrencyCode
                };
            }

            // Either PromotionCode or OrdersOverAmount must be set.
            if (!string.IsNullOrEmpty(promotionFeedItem.PromotionCode))
            {
                asset.PromotionAsset.PromotionCode = promotionFeedItem.PromotionCode;
            }
            else
            {
                asset.PromotionAsset.OrdersOverAmount = new Money
                {
                    AmountMicros = promotionFeedItem.OrdersOverAmount.AmountMicros,
                    CurrencyCode = promotionFeedItem.OrdersOverAmount.CurrencyCode
                };
            }

            // Set the start and end dates if set in the existing extension.
            if (extensionFeedItem.HasStartDateTime)
            {
                asset.PromotionAsset.StartDate = DateTime.Parse(extensionFeedItem.StartDateTime)
                                                 .ToString("yyyy-MM-dd");
            }

            if (extensionFeedItem.HasEndDateTime)
            {
                asset.PromotionAsset.EndDate = DateTime.Parse(extensionFeedItem.EndDateTime)
                                               .ToString("yyyy-MM-dd");
            }

            asset.PromotionAsset.AdScheduleTargets.Add(extensionFeedItem.AdSchedules);
            asset.FinalUrls.Add(promotionFeedItem.FinalUrls);
            asset.FinalMobileUrls.Add(promotionFeedItem.FinalMobileUrls);
            asset.UrlCustomParameters.Add(promotionFeedItem.UrlCustomParameters);

            // Build an operation to create the Promotion asset.
            AssetOperation operation = new AssetOperation
            {
                Create = asset
            };

            // Issue the request and return the resource name of the new Promotion asset.
            MutateAssetsResponse response = assetServiceClient.MutateAssets(
                customerId.ToString(), new[] { operation });

            Console.WriteLine("Created Promotion asset with resource name " +
                              $"{response.Results.First().ResourceName}");
            return(response.Results.First().ResourceName);
        }