private static void associateSitelinkFeedItemsWithCampaign(
CampaignFeedService campaignFeedService, SiteLinksFeed siteLinksFeed,
List<long> siteLinkFeedItemIds, long campaignId)
{
// Create a custom matching function that matches the given feed items to
// the campaign.
RequestContextOperand requestContextOperand = new RequestContextOperand();
requestContextOperand.contextType = RequestContextOperandContextType.FEED_ITEM_ID;
Function function = new Function();
function.lhsOperand = new FunctionArgumentOperand[] {requestContextOperand};
function.@operator = FunctionOperator.IN;
List<FunctionArgumentOperand> operands = new List<FunctionArgumentOperand>();
foreach (long feedItemId in siteLinkFeedItemIds) {
ConstantOperand constantOperand = new ConstantOperand();
constantOperand.longValue = feedItemId;
constantOperand.type = ConstantOperandConstantType.LONG;
operands.Add(constantOperand);
}
function.rhsOperand = operands.ToArray();
// Create upgraded sitelinks for the campaign. Use the sitelinks feed we
// created, and restrict feed items by matching function.
CampaignFeed campaignFeed = new CampaignFeed();
campaignFeed.feedId = siteLinksFeed.SiteLinksFeedId;
campaignFeed.campaignId = campaignId;
campaignFeed.matchingFunction = function;
campaignFeed.placeholderTypes = new int[] {PLACEHOLDER_SITELINKS};
CampaignFeedOperation operation = new CampaignFeedOperation();
operation.operand = campaignFeed;
operation.@operator = Operator.ADD;
campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
}