/// <summary>
    /// Gets the list of feed items that are used by a campaign through a given
    /// campaign feed.
    /// </summary>
    /// <param name="campaignFeed">The campaign feed.</param>
    /// <returns>The list of feed items.</returns>
    private List<long> GetFeedItemsForCampaign(CampaignFeed campaignFeed) {
      List<long> feedItems = new List<long>();

      switch (campaignFeed.matchingFunction.@operator) {
        case FunctionOperator.IN:
          // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
          // Extract feedItems if applicable.
          feedItems.AddRange(GetFeedItemsFromArgument(campaignFeed.matchingFunction));

          break;

        case FunctionOperator.AND:
          // Check each condition.

          foreach (FunctionArgumentOperand argument in campaignFeed.matchingFunction.lhsOperand) {
            // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
            // Extract feedItems if applicable.
            if (argument is FunctionOperand) {
              FunctionOperand operand = (argument as FunctionOperand);
              if (operand.value.@operator == FunctionOperator.IN) {
                feedItems.AddRange(GetFeedItemsFromArgument(operand.value));
              }
            }
          }
          break;

        default:
          // There are no other matching functions involving feeditem ids.
          break;
      }

      return feedItems;
    }
Beispiel #2
0
        /// <summary>
        /// Creates a campaign feed, which tells Google Ads which campaigns to use the provided
        /// data with.
        /// </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">The campaign to receive the feed.</param>
        /// <param name="feed">The feed to connect to the campaign.</param>
        private void CreateCampaignFeed(GoogleAdsClient client, long customerId, long campaignId,
                                        Feed feed)
        {
            CampaignFeedServiceClient campaignFeedServiceClient =
                client.GetService(Services.V4.CampaignFeedService);

            // Fetch the Feed Item IDs and collapse them into a single comma-separated string.
            List <long>  feedItemIds           = feed.Attributes.Select(attr => attr.Id.Value).ToList();
            string       aggregatedFeedItemIds = string.Join(",", feedItemIds);
            CampaignFeed campaignFeed          = new CampaignFeed()
            {
                Feed             = feed.ResourceName,
                Campaign         = ResourceNames.Campaign(customerId, campaignId),
                MatchingFunction = new MatchingFunction()
                {
                    FunctionString = $"AND(IN(FEED_ITEM_ID,{{ {aggregatedFeedItemIds} }})," +
                                     "EQUALS(CONTEXT.DEVICE,'Mobile'))"
                }
            };

            campaignFeed.PlaceholderTypes.Add(PlaceholderTypeEnum.Types.PlaceholderType.Sitelink);

            CampaignFeedOperation operation = new CampaignFeedOperation()
            {
                Create = campaignFeed
            };

            MutateCampaignFeedsResponse response = campaignFeedServiceClient.MutateCampaignFeeds(
                customerId.ToString(), new[] { operation });

            Console.WriteLine($"Created campaign feed '{response.Results.First().ResourceName}'");
        }
Beispiel #3
0
        /// <summary>
        /// Gets the platform restrictions for sitelinks in a campaign.
        /// </summary>
        /// <param name="campaignFeed">The campaign feed.</param>
        /// <returns>The platform restrictions.</returns>
        private ExtensionSettingPlatform GetPlatformRestrictionsForCampaign(
            CampaignFeed campaignFeed)
        {
            string platformRestrictions = "NONE";

            if (campaignFeed.matchingFunction.@operator == FunctionOperator.AND)
            {
                foreach (FunctionArgumentOperand argument in campaignFeed.matchingFunction.lhsOperand)
                {
                    // Check if matchingFunction is of the form EQUALS(CONTEXT.DEVICE, 'Mobile').
                    if (argument is FunctionOperand)
                    {
                        FunctionOperand operand = (argument as FunctionOperand);
                        if (operand.value.@operator == FunctionOperator.EQUALS)
                        {
                            RequestContextOperand requestContextOperand = operand.value.lhsOperand[0] as
                                                                          RequestContextOperand;
                            if (requestContextOperand != null && requestContextOperand.contextType ==
                                RequestContextOperandContextType.DEVICE_PLATFORM)
                            {
                                platformRestrictions = (operand.value.rhsOperand[0] as ConstantOperand)
                                                       .stringValue;
                            }
                        }
                    }
                }
            }

            return((ExtensionSettingPlatform)Enum.Parse(typeof(ExtensionSettingPlatform),
                                                        platformRestrictions, true));
        }
 /// <summary>Snippet for GetCampaignFeed</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignFeed()
 {
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/campaignFeeds/[CAMPAIGN_ID]~[FEED_ID]";
     // Make the request
     CampaignFeed response = campaignFeedServiceClient.GetCampaignFeed(resourceName);
 }
 /// <summary>Snippet for GetCampaignFeed</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignFeedResourceNames()
 {
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     CampaignFeedName resourceName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[FEED_ID]");
     // Make the request
     CampaignFeed response = campaignFeedServiceClient.GetCampaignFeed(resourceName);
 }
        /// <summary>Snippet for GetCampaignFeedAsync</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 GetCampaignFeedAsync()
        {
            // Create client
            CampaignFeedServiceClient campaignFeedServiceClient = await CampaignFeedServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaignFeeds/[CAMPAIGN_FEED]";
            // Make the request
            CampaignFeed response = await campaignFeedServiceClient.GetCampaignFeedAsync(resourceName);
        }
Beispiel #7
0
        /// <summary>Snippet for GetCampaignFeedAsync</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 GetCampaignFeedResourceNamesAsync()
        {
            // Create client
            CampaignFeedServiceClient campaignFeedServiceClient = await CampaignFeedServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignFeedName resourceName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER]", "[CAMPAIGN_FEED]");
            // Make the request
            CampaignFeed response = await campaignFeedServiceClient.GetCampaignFeedAsync(resourceName);
        }
 /// <summary>Snippet for GetCampaignFeed</summary>
 public void GetCampaignFeedResourceNames()
 {
     // Snippet: GetCampaignFeed(CampaignFeedName, CallSettings)
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     CampaignFeedName resourceName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER]", "[CAMPAIGN_FEED]");
     // Make the request
     CampaignFeed response = campaignFeedServiceClient.GetCampaignFeed(resourceName);
     // End snippet
 }
    /// <summary>
    /// Deletes a campaign feed.
    /// </summary>
    /// <param name="user">The user.</param>
    /// <param name="campaignFeed">The campaign feed.</param>
    /// <returns></returns>
    private CampaignFeed DeleteCampaignFeed(AdWordsUser user, CampaignFeed campaignFeed) {
      CampaignFeedService campaignFeedService = (CampaignFeedService) user.GetService(
          AdWordsService.v201509.CampaignFeedService);

      CampaignFeedOperation operation = new CampaignFeedOperation() {
        operand = campaignFeed,
        @operator = Operator.REMOVE
      };

      return campaignFeedService.mutate(new CampaignFeedOperation[] { operation }).value[0];
    }
 /// <summary>Snippet for GetCampaignFeed</summary>
 public void GetCampaignFeed()
 {
     // Snippet: GetCampaignFeed(string, CallSettings)
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/campaignFeeds/[CAMPAIGN_FEED]";
     // Make the request
     CampaignFeed response = campaignFeedServiceClient.GetCampaignFeed(resourceName);
     // End snippet
 }
Beispiel #11
0
 /// <summary>Snippet for GetCampaignFeed</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignFeedRequestObject()
 {
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     GetCampaignFeedRequest request = new GetCampaignFeedRequest
     {
         ResourceNameAsCampaignFeedName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER]", "[CAMPAIGN_FEED]"),
     };
     // Make the request
     CampaignFeed response = campaignFeedServiceClient.GetCampaignFeed(request);
 }
Beispiel #12
0
        private static void CreateSitelinksCampaignFeed(AdWordsUser user,
                                                        SitelinksDataHolder sitelinksData, long campaignId)
        {
            using (CampaignFeedService campaignFeedService =
                       (CampaignFeedService)user.GetService(AdWordsService.v201809.CampaignFeedService))
            {
                // Construct a matching function that associates the sitelink feeditems
                // to the campaign, and set the device preference to Mobile. See the
                // matching function guide at
                // https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
                // for more details.
                string matchingFunctionString = string.Format(@"
          AND(
            IN(FEED_ITEM_ID, {{{0}}}),
            EQUALS(CONTEXT.DEVICE, 'Mobile')
          )", string.Join(",", sitelinksData.FeedItemIds));

                CampaignFeed campaignFeed = new CampaignFeed()
                {
                    feedId           = sitelinksData.FeedId,
                    campaignId       = campaignId,
                    matchingFunction = new Function()
                    {
                        functionString = matchingFunctionString
                    },
                    // Specifying placeholder types on the CampaignFeed allows the same feed
                    // to be used for different placeholders in different Campaigns.
                    placeholderTypes = new int[]
                    {
                        PLACEHOLDER_SITELINKS
                    }
                };

                CampaignFeedOperation operation = new CampaignFeedOperation()
                {
                    operand   = campaignFeed,
                    @operator = Operator.ADD
                };

                CampaignFeedReturnValue result = campaignFeedService.mutate(
                    new CampaignFeedOperation[]
                {
                    operation
                });

                foreach (CampaignFeed savedCampaignFeed in result.value)
                {
                    Console.WriteLine("Campaign with ID {0} was associated with feed with ID {1}",
                                      savedCampaignFeed.campaignId, savedCampaignFeed.feedId);
                }
            }
        }
Beispiel #13
0
        /// <summary>Snippet for GetCampaignFeedAsync</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 GetCampaignFeedRequestObjectAsync()
        {
            // Create client
            CampaignFeedServiceClient campaignFeedServiceClient = await CampaignFeedServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignFeedRequest request = new GetCampaignFeedRequest
            {
                ResourceNameAsCampaignFeedName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[FEED_ID]"),
            };
            // Make the request
            CampaignFeed response = await campaignFeedServiceClient.GetCampaignFeedAsync(request);
        }
        /// <summary>Snippet for GetCampaignFeedAsync</summary>
        public async Task GetCampaignFeedAsync()
        {
            // Snippet: GetCampaignFeedAsync(string, CallSettings)
            // Additional: GetCampaignFeedAsync(string, CancellationToken)
            // Create client
            CampaignFeedServiceClient campaignFeedServiceClient = await CampaignFeedServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/campaignFeeds/[CAMPAIGN_ID]~[FEED_ID]";
            // Make the request
            CampaignFeed response = await campaignFeedServiceClient.GetCampaignFeedAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetCampaignFeedAsync</summary>
        public async Task GetCampaignFeedResourceNamesAsync()
        {
            // Snippet: GetCampaignFeedAsync(CampaignFeedName, CallSettings)
            // Additional: GetCampaignFeedAsync(CampaignFeedName, CancellationToken)
            // Create client
            CampaignFeedServiceClient campaignFeedServiceClient = await CampaignFeedServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignFeedName resourceName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[FEED_ID]");
            // Make the request
            CampaignFeed response = await campaignFeedServiceClient.GetCampaignFeedAsync(resourceName);

            // End snippet
        }
Beispiel #16
0
        /// <summary>
        /// Deletes a campaign feed.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignFeed">The campaign feed.</param>
        /// <returns></returns>
        private CampaignFeed DeleteCampaignFeed(AdWordsUser user, CampaignFeed campaignFeed)
        {
            using (CampaignFeedService campaignFeedService = (CampaignFeedService)user.GetService(
                       AdWordsService.v201710.CampaignFeedService)) {
                CampaignFeedOperation operation = new CampaignFeedOperation()
                {
                    operand   = campaignFeed,
                    @operator = Operator.REMOVE
                };

                CampaignFeed retval = campaignFeedService.mutate(
                    new CampaignFeedOperation[] { operation }).value[0];
                return(retval);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Gets the list of feed items that are used by a campaign through a given
        /// campaign feed.
        /// </summary>
        /// <param name="campaignFeed">The campaign feed.</param>
        /// <returns>The list of feed items.</returns>
        private List <long> GetFeedItemsForCampaign(CampaignFeed campaignFeed)
        {
            List <long> feedItems = new List <long>();

            if (campaignFeed.matchingFunction.lhsOperand.Length == 1 &&
                campaignFeed.matchingFunction.lhsOperand[0] is RequestContextOperand &&
                (campaignFeed.matchingFunction.lhsOperand[0] as RequestContextOperand).contextType ==
                RequestContextOperandContextType.FEED_ITEM_ID &&
                campaignFeed.matchingFunction.@operator == FunctionOperator.IN)
            {
                foreach (ConstantOperand argument in campaignFeed.matchingFunction.rhsOperand)
                {
                    feedItems.Add(argument.longValue);
                }
            }
            return(feedItems);
        }
        /// <summary>Snippet for GetCampaignFeedAsync</summary>
        public async Task GetCampaignFeedRequestObjectAsync()
        {
            // Snippet: GetCampaignFeedAsync(GetCampaignFeedRequest, CallSettings)
            // Additional: GetCampaignFeedAsync(GetCampaignFeedRequest, CancellationToken)
            // Create client
            CampaignFeedServiceClient campaignFeedServiceClient = await CampaignFeedServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignFeedRequest request = new GetCampaignFeedRequest
            {
                ResourceNameAsCampaignFeedName = CampaignFeedName.FromCustomerCampaignFeed("[CUSTOMER]", "[CAMPAIGN_FEED]"),
            };
            // Make the request
            CampaignFeed response = await campaignFeedServiceClient.GetCampaignFeedAsync(request);

            // End snippet
        }
        public void GetCampaignFeed2()
        {
            Mock <CampaignFeedService.CampaignFeedServiceClient> mockGrpcClient = new Mock <CampaignFeedService.CampaignFeedServiceClient>(MockBehavior.Strict);
            GetCampaignFeedRequest request = new GetCampaignFeedRequest
            {
                ResourceName = new CampaignFeedName("[CUSTOMER]", "[CAMPAIGN_FEED]").ToString(),
            };
            CampaignFeed expectedResponse = new CampaignFeed
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignFeed(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            CampaignFeedServiceClient client = new CampaignFeedServiceClientImpl(mockGrpcClient.Object, null);
            CampaignFeed response            = client.GetCampaignFeed(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetCampaignFeedAsync2()
        {
            Mock <CampaignFeedService.CampaignFeedServiceClient> mockGrpcClient = new Mock <CampaignFeedService.CampaignFeedServiceClient>(MockBehavior.Strict);
            GetCampaignFeedRequest request = new GetCampaignFeedRequest
            {
                ResourceName = new CampaignFeedName("[CUSTOMER]", "[CAMPAIGN_FEED]").ToString(),
            };
            CampaignFeed expectedResponse = new CampaignFeed
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignFeedAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <CampaignFeed>(Task.FromResult(expectedResponse), null, null, null, null));
            CampaignFeedServiceClient client = new CampaignFeedServiceClientImpl(mockGrpcClient.Object, null);
            CampaignFeed response            = await client.GetCampaignFeedAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Beispiel #21
0
        /// <summary>
        /// Creates the campaign feed.
        /// </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">The campaign ID for which the affiliate location extensions
        /// are added.</param>
        /// <param name="feedMapping">The affliate location extension feedmapping for
        /// <paramref name="feedResourceName"/></param>
        /// <param name="feedResourceName">The feed resource name.</param>
        /// <param name="chainId">The retail chain ID.</param>
        private static void CreateCampaignFeed(GoogleAdsClient client, long customerId,
                                               long campaignId, FeedMapping feedMapping, string feedResourceName, long chainId)
        {
            // Get the CampaignFeedService.
            CampaignFeedServiceClient campaignFeedService = client.GetService(
                Services.V5.CampaignFeedService);

            long   attributeIdForChainId = GetAttributeIdForChainId(feedMapping);
            string feedId = FeedName.Parse(feedResourceName).FeedId;

            string matchingFunction =
                $"IN(FeedAttribute[{feedId}, {attributeIdForChainId}], {chainId})";
            // Adds a CampaignFeed that associates the feed with this campaign for
            // the AFFILIATE_LOCATION placeholder type.
            CampaignFeed campaignFeed = new CampaignFeed()
            {
                Feed             = feedResourceName,
                PlaceholderTypes = { PlaceholderType.AffiliateLocation },
                MatchingFunction = new MatchingFunction()
                {
                    FunctionString = matchingFunction
                },
                Campaign = ResourceNames.Campaign(customerId, campaignId),
            };

            CampaignFeedOperation operation = new CampaignFeedOperation()
            {
                Create = campaignFeed
            };

            MutateCampaignFeedsResponse campaignFeedsResponse =
                campaignFeedService.MutateCampaignFeeds(
                    customerId.ToString(), new[] { operation });

            // Displays the result.
            string addedCampaignFeed = campaignFeedsResponse.Results[0].ResourceName;

            Console.WriteLine($"Campaign feed created with resource name: {addedCampaignFeed}.");
            return;
        }
    private static void createSitelinksCampaignFeed(AdWordsUser user,
      SitelinksDataHolder sitelinksData, long campaignId) {
      // Get the CampaignFeedService.
      CampaignFeedService campaignFeedService =
        (CampaignFeedService) user.GetService(AdWordsService.v201509.CampaignFeedService);

      // Construct a matching function that associates the sitelink feeditems
      // to the campaign, and set the device preference to Mobile. See the
      // matching function guide at
      // https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
      // for more details.
      string matchingFunctionString = string.Format(@"
          AND(
            IN(FEED_ITEM_ID, {{{0}}}),
            EQUALS(CONTEXT.DEVICE, 'Mobile')
          )",
          string.Join(",", sitelinksData.FeedItemIds));


      CampaignFeed campaignFeed = new CampaignFeed() {
        feedId = sitelinksData.FeedId,
        campaignId = campaignId,
        matchingFunction = new Function() {
          functionString = matchingFunctionString
        },
        // Specifying placeholder types on the CampaignFeed allows the same feed
        // to be used for different placeholders in different Campaigns.
        placeholderTypes = new int[] { PLACEHOLDER_SITELINKS }
      };

      CampaignFeedOperation operation = new CampaignFeedOperation();
      operation.operand = campaignFeed;
      operation.@operator = Operator.ADD;
      CampaignFeedReturnValue result =
          campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
      foreach (CampaignFeed savedCampaignFeed in result.value) {
        Console.WriteLine("Campaign with ID {0} was associated with feed with ID {1}",
            savedCampaignFeed.campaignId, savedCampaignFeed.feedId);
      }
    }
Beispiel #23
0
        private static void createSiteLinksCampaignFeed(AdWordsUser user,
                                                        SiteLinksDataHolder siteLinksData, long campaignId)
        {
            // Get the CampaignFeedService.
            CampaignFeedService campaignFeedService =
                (CampaignFeedService)user.GetService(AdWordsService.v201406.CampaignFeedService);

            // Map the feed item ids to the campaign using an IN operation.
            RequestContextOperand feedItemRequestContextOperand = new RequestContextOperand();

            feedItemRequestContextOperand.contextType = RequestContextOperandContextType.FEED_ITEM_ID;

            List <FunctionArgumentOperand> feedItemOperands = new List <FunctionArgumentOperand>();

            foreach (long feedItemId in siteLinksData.SiteLinkFeedItemIds)
            {
                ConstantOperand feedItemOperand = new ConstantOperand();
                feedItemOperand.longValue = feedItemId;
                feedItemOperand.type      = ConstantOperandConstantType.LONG;
                feedItemOperands.Add(feedItemOperand);
            }

            Function feedItemfunction = new Function();

            feedItemfunction.lhsOperand = new FunctionArgumentOperand[] { feedItemRequestContextOperand };
            feedItemfunction.@operator  = FunctionOperator.IN;
            feedItemfunction.rhsOperand = feedItemOperands.ToArray();

            // Optional: to target to a platform, define a function and 'AND' it with
            // the feed item ID link:
            RequestContextOperand platformRequestContextOperand = new RequestContextOperand();

            platformRequestContextOperand.contextType = RequestContextOperandContextType.DEVICE_PLATFORM;

            ConstantOperand platformOperand = new ConstantOperand();

            platformOperand.stringValue = "Mobile";
            platformOperand.type        = ConstantOperandConstantType.STRING;

            Function platformFunction = new Function();

            platformFunction.lhsOperand = new FunctionArgumentOperand[] { platformRequestContextOperand };
            platformFunction.@operator  = FunctionOperator.EQUALS;
            platformFunction.rhsOperand = new FunctionArgumentOperand[] { platformOperand };

            // Combine the two functions using an AND operation.
            FunctionOperand feedItemFunctionOperand = new FunctionOperand();

            feedItemFunctionOperand.value = feedItemfunction;

            FunctionOperand platformFunctionOperand = new FunctionOperand();

            platformFunctionOperand.value = platformFunction;

            Function combinedFunction = new Function();

            combinedFunction.@operator  = FunctionOperator.AND;
            combinedFunction.lhsOperand = new FunctionArgumentOperand[] {
                feedItemFunctionOperand, platformFunctionOperand
            };

            CampaignFeed campaignFeed = new CampaignFeed();

            campaignFeed.feedId           = siteLinksData.SiteLinksFeedId;
            campaignFeed.campaignId       = campaignId;
            campaignFeed.matchingFunction = combinedFunction;
            // Specifying placeholder types on the CampaignFeed allows the same feed
            // to be used for different placeholders in different Campaigns.
            campaignFeed.placeholderTypes = new int[] { PLACEHOLDER_SITELINKS };

            CampaignFeedOperation operation = new CampaignFeedOperation();

            operation.operand   = campaignFeed;
            operation.@operator = Operator.ADD;
            CampaignFeedReturnValue result =
                campaignFeedService.mutate(new CampaignFeedOperation[] { operation });

            foreach (CampaignFeed savedCampaignFeed in result.value)
            {
                Console.WriteLine("Campaign with ID {0} was associated with feed with ID {1}",
                                  savedCampaignFeed.campaignId, savedCampaignFeed.feedId);
            }
        }
    /// <summary>
    /// Gets the platform restrictions for sitelinks in a campaign.
    /// </summary>
    /// <param name="campaignFeed">The campaign feed.</param>
    /// <returns>The platform restrictions.</returns>
    private ExtensionSettingPlatform GetPlatformRestrictionsForCampaign(
          CampaignFeed campaignFeed) {
      string platformRestrictions = "NONE";

      if (campaignFeed.matchingFunction.@operator == FunctionOperator.AND) {
        foreach (FunctionArgumentOperand argument in campaignFeed.matchingFunction.lhsOperand) {
          // Check if matchingFunction is of the form EQUALS(CONTEXT.DEVICE, 'Mobile').
          if (argument is FunctionOperand) {
            FunctionOperand operand = (argument as FunctionOperand);
            if (operand.value.@operator == FunctionOperator.EQUALS) {
              RequestContextOperand requestContextOperand = operand.value.lhsOperand[0] as
                  RequestContextOperand;
              if (requestContextOperand != null && requestContextOperand.contextType ==
                  RequestContextOperandContextType.DEVICE_PLATFORM) {
                platformRestrictions = (operand.value.rhsOperand[0] as ConstantOperand)
                      .stringValue;
              }
            }
          }
        }
      }

      return (ExtensionSettingPlatform) Enum.Parse(typeof(ExtensionSettingPlatform),
              platformRestrictions, true);
    }