Exemplo n.º 1
0
        private static void RestrictFeedItemToAdGroup(AdWordsUser user,
                                                      SitelinksDataHolder sitelinksData, long?adGroupId)
        {
            // Optional: Restrict the first feed item to only serve with ads for the
            // specified ad group ID.
            FeedItemAdGroupTarget adGroupTarget = new FeedItemAdGroupTarget()
            {
                feedId     = sitelinksData.FeedId,
                feedItemId = sitelinksData.FeedItemIds[0],
                adGroupId  = adGroupId.Value
            };

            using (FeedItemTargetService feedItemTargetService =
                       (FeedItemTargetService)user.GetService(
                           AdWordsService.v201809.FeedItemTargetService))
            {
                FeedItemTargetOperation operation = new FeedItemTargetOperation()
                {
                    @operator = Operator.ADD,
                    operand   = adGroupTarget
                };

                FeedItemTargetReturnValue retval = feedItemTargetService.mutate(
                    new FeedItemTargetOperation[]
                {
                    operation
                });
                FeedItemAdGroupTarget newAdGroupTarget = (FeedItemAdGroupTarget)retval.value[0];
                Console.WriteLine(
                    "Feed item target for feed ID {0} and feed item ID {1}" +
                    " was created to restrict serving to ad group ID {2}", newAdGroupTarget.feedId,
                    newAdGroupTarget.feedItemId, newAdGroupTarget.adGroupId);
            }
        }
        private static void RestrictFeedItemToGeoTarget(AdWordsUser user,
                                                        FeedItem feedItem, long locationId)
        {
            FeedItemCriterionTarget criterionTarget = new FeedItemCriterionTarget()
            {
                feedId     = feedItem.feedId,
                feedItemId = feedItem.feedItemId,
                // The IDs can be found in the documentation or retrieved with the
                // LocationCriterionService.
                criterion = new Location()
                {
                    id = locationId,
                }
            };

            using (FeedItemTargetService feedItemTargetService = (FeedItemTargetService)user.GetService(
                       AdWordsService.v201802.FeedItemTargetService)) {
                FeedItemTargetOperation operation = new FeedItemTargetOperation()
                {
                    @operator = Operator.ADD,
                    operand   = criterionTarget
                };


                FeedItemTargetReturnValue retval = feedItemTargetService.mutate(
                    new FeedItemTargetOperation[] { operation });
                FeedItemCriterionTarget newLocationTarget = (FeedItemCriterionTarget)retval.value[0];
                Console.WriteLine("Feed item target for feed ID {0} and feed item ID {1}" +
                                  " was created to restrict serving to location ID {2}",
                                  newLocationTarget.feedId, newLocationTarget.feedItemId,
                                  newLocationTarget.criterion.id);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Restricts the feed item to an ad group.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="feedItem">The feed item.</param>
        /// <param name="adGroupId">The ad group ID.</param>
        private static void RestrictFeedItemToAdGroup(AdWordsUser user, FeedItem feedItem,
                                                      long?adGroupId)
        {
            FeedItemAdGroupTarget adGroupTarget = new FeedItemAdGroupTarget()
            {
                feedId     = feedItem.feedId,
                feedItemId = feedItem.feedItemId,
                adGroupId  = adGroupId.Value
            };

            using (FeedItemTargetService feedItemTargetService =
                       (FeedItemTargetService)user.GetService(
                           AdWordsService.v201802.FeedItemTargetService))
            {
                FeedItemTargetOperation operation = new FeedItemTargetOperation()
                {
                    @operator = Operator.ADD,
                    operand   = adGroupTarget
                };

                FeedItemTargetReturnValue retval = feedItemTargetService.mutate(
                    new FeedItemTargetOperation[]
                {
                    operation
                });
                FeedItemAdGroupTarget newAdGroupTarget = (FeedItemAdGroupTarget)retval.value[0];
                Console.WriteLine(
                    "Feed item target for feed ID {0} and feed item ID {1}" +
                    " was created to restrict serving to ad group ID {2}", newAdGroupTarget.feedId,
                    newAdGroupTarget.feedItemId, newAdGroupTarget.adGroupId);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Restrict a Feed Item to an AdGroup
        /// </summary>
        /// <param name="user">Adwords User Object</param>
        /// <param name="feedItem">Feed Item</param>
        /// <param name="adGroupId">Ad Group ID</param>
        /// <returns>FeedItemAdGroupTarget Object with Details of Updated SiteLink</returns>
        public FeedItemAdGroupTarget RestrictFeedItemToAdGroup(AdWordsUser user, FeedItem feedItem, long adGroupId)
        {
            FeedItemTargetService feedItemTargetService = (FeedItemTargetService)user.GetService(AdWordsService.v201809.FeedItemTargetService);

            FeedItemAdGroupTarget feedItemAdGroupTarget = new FeedItemAdGroupTarget();

            feedItemAdGroupTarget.feedId     = feedItem.feedId;
            feedItemAdGroupTarget.feedItemId = feedItem.feedItemId;
            feedItemAdGroupTarget.targetType = FeedItemTargetType.AD_GROUP;
            feedItemAdGroupTarget.adGroupId  = adGroupId;

            FeedItemTargetOperation feedItemTargetOperation = new FeedItemTargetOperation();

            feedItemTargetOperation.operand   = feedItemAdGroupTarget;
            feedItemTargetOperation.@operator = Operator.SET;

            try
            {
                FeedItemTargetReturnValue feedItemTargetReturnValue = feedItemTargetService.mutate(new[] { feedItemTargetOperation });
                if (feedItemTargetReturnValue.value != null && feedItemTargetReturnValue.value.Length > 0)
                {
                    FeedItemAdGroupTarget modifiedTargetItem = (FeedItemAdGroupTarget)feedItemTargetReturnValue.value[0];
                    Logger.Log(Logger.LogType.INFO, "Modification Successful for Feed(ID): " + feedItem.feedId + " with FeedItem(ID): " + feedItem.feedItemId);
                    return(modifiedTargetItem);
                }
                else
                {
                    Logger.Log(Logger.LogType.WARNING, "Nothing Modified for Feed(ID): " + feedItem.feedId + " with FeedItem(ID): " + feedItem.feedItemId);
                    return(null);
                }
            }
            catch (AdWordsApiException ex)
            {
                Logger.Log(Logger.LogType.EXCEPTION, Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException);
                return(null);
            }
        }