Esempio n. 1
0
        /// <summary>
        /// Modifies SiteLink Extension at Customer Level
        /// </summary>
        /// <param name="user">Adwords User Object</param>
        /// <param name="sitelinkFeedItem">SiteLinkFeedItem with Details</param>
        /// <returns>Updated CustomerExtensionSettings</returns>
        public CustomerExtensionSetting UpdateSiteLinkAtCustomerLevelUsingCustExtSetService(AdWordsUser user, SitelinkFeedItem sitelinkFeedItem)
        {
            CustomerExtensionSettingService customerExtensionSettingService = (CustomerExtensionSettingService)user.GetService(AdWordsService.v201809.CustomerExtensionSettingService);

            ExtensionFeedItem[] extensionFeedItems = new[] { sitelinkFeedItem };
            ExtensionSetting    extensionSetting   = new ExtensionSetting();

            extensionSetting.extensions = extensionFeedItems;

            CustomerExtensionSetting customerExtensionSetting = new CustomerExtensionSetting();

            customerExtensionSetting.extensionType    = FeedType.SITELINK;
            customerExtensionSetting.extensionSetting = extensionSetting;

            CustomerExtensionSettingOperation modifyOperation = new CustomerExtensionSettingOperation();

            modifyOperation.operand   = customerExtensionSetting;
            modifyOperation.@operator = Operator.SET;

            try
            {
                CustomerExtensionSettingReturnValue returnValue = customerExtensionSettingService.mutate(new[] { modifyOperation });
                if (returnValue.value != null && returnValue.value.Length > 0)
                {
                    CustomerExtensionSetting modifiedExtensionSetting = returnValue.value[0];
                    Logger.Log(Logger.LogType.INFO, "Modification Successful for Feed(ID): " + sitelinkFeedItem.feedId + " with FeedItem(ID): " + sitelinkFeedItem.feedItemId);
                    return(modifiedExtensionSetting);
                }
                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);
            }
        }
        /// <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);
                }
            }
        }