/// <summary> /// Creates a FeedItemOperation that will create a FeedItem with the /// specified values and ad group target when sent to /// FeedItemService.mutate. /// </summary> /// <param name="adCustomizerFeed">The ad customizer feed.</param> /// <param name="name">The value for the name attribute of the FeedItem. /// </param> /// <param name="price">The value for the price attribute of the FeedItem. /// </param> /// <param name="date">The value for the date attribute of the FeedItem. /// </param> /// <param name="adGroupId">The ID of the ad group to target with the /// FeedItem.</param> /// <returns>A new FeedItemOperation for adding a FeedItem.</returns> private static FeedItemOperation CreateFeedItemAddOperation(AdCustomizerFeed adCustomizerFeed, string name, string price, String date, long adGroupId) { FeedItem feedItem = new FeedItem(); feedItem.feedId = adCustomizerFeed.feedId; List<FeedItemAttributeValue> attributeValues = new List<FeedItemAttributeValue>(); // FeedAttributes appear in the same order as they were created // - Name, Price, Date. See CreateCustomizerFeed method for details. FeedItemAttributeValue nameAttributeValue = new FeedItemAttributeValue(); nameAttributeValue.feedAttributeId = adCustomizerFeed.feedAttributes[0].id; nameAttributeValue.stringValue = name; attributeValues.Add(nameAttributeValue); FeedItemAttributeValue priceAttributeValue = new FeedItemAttributeValue(); priceAttributeValue.feedAttributeId = adCustomizerFeed.feedAttributes[1].id; priceAttributeValue.stringValue = price; attributeValues.Add(priceAttributeValue); FeedItemAttributeValue dateAttributeValue = new FeedItemAttributeValue(); dateAttributeValue.feedAttributeId = adCustomizerFeed.feedAttributes[2].id; dateAttributeValue.stringValue = date; attributeValues.Add(dateAttributeValue); feedItem.attributeValues = attributeValues.ToArray(); feedItem.adGroupTargeting = new FeedItemAdGroupTargeting(); feedItem.adGroupTargeting.TargetingAdGroupId = adGroupId; FeedItemOperation feedItemOperation = new FeedItemOperation(); feedItemOperation.operand = feedItem; feedItemOperation.@operator = Operator.ADD; return feedItemOperation; }
private static FeedItemOperation newSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, String text, String finalUrl) { // Create the FeedItemAttributeValues for our text values. FeedItemAttributeValue linkTextAttributeValue = new FeedItemAttributeValue(); linkTextAttributeValue.feedAttributeId = sitelinksData.LinkTextFeedAttributeId; linkTextAttributeValue.stringValue = text; FeedItemAttributeValue linkFinalUrlAttributeValue = new FeedItemAttributeValue(); linkFinalUrlAttributeValue.feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId; linkFinalUrlAttributeValue.stringValues = new string[] { finalUrl }; // Create the feed item and operation. FeedItem item = new FeedItem(); item.feedId = sitelinksData.FeedId; item.attributeValues = new FeedItemAttributeValue[] {linkTextAttributeValue, linkFinalUrlAttributeValue}; FeedItemOperation operation = new FeedItemOperation(); operation.operand = item; operation.@operator = Operator.ADD; return operation; }