private static void createSitelinksCampaignFeed(AdWordsUser user, SitelinksDataHolder sitelinksData, long campaignId) { // Get the CampaignFeedService. CampaignFeedService campaignFeedService = (CampaignFeedService) user.GetService(AdWordsService.v201502.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); } }
/// <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.v201502.CampaignFeedService); CampaignFeedOperation operation = new CampaignFeedOperation() { operand = campaignFeed, @operator = Operator.REMOVE }; return campaignFeedService.mutate(new CampaignFeedOperation[] { operation }).value[0]; }