private static FeedItemOperation NewSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, string text, string finalUrl, string line2, string line3) { return(NewSitelinkFeedItemAddOperation(sitelinksData, text, finalUrl, line2, line3, false)); }
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 FeedItemOperation NewSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, string text, string finalUrl, string line2, string line3, bool restrictToLop) { // Create the FeedItemAttributeValues for our text values. FeedItemAttributeValue linkTextAttributeValue = new FeedItemAttributeValue() { feedAttributeId = sitelinksData.LinkTextFeedAttributeId, stringValue = text }; FeedItemAttributeValue linkFinalUrlAttributeValue = new FeedItemAttributeValue() { feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId, stringValues = new string[] { finalUrl } }; FeedItemAttributeValue line2AttributeValue = new FeedItemAttributeValue() { feedAttributeId = sitelinksData.Line2FeedAttributeId, stringValue = line2 }; FeedItemAttributeValue line3AttributeValue = new FeedItemAttributeValue() { feedAttributeId = sitelinksData.Line3FeedAttributeId, stringValue = line3 }; // Create the feed item and operation. FeedItem item = new FeedItem() { feedId = sitelinksData.FeedId, attributeValues = new FeedItemAttributeValue[] { linkTextAttributeValue, linkFinalUrlAttributeValue, line2AttributeValue, line3AttributeValue } }; // OPTIONAL: Restrict targeting only to people physically within the location. if (restrictToLop) { item.geoTargetingRestriction = new FeedItemGeoRestriction() { geoRestriction = GeoRestriction.LOCATION_OF_PRESENCE }; } return(new FeedItemOperation() { operand = item, @operator = Operator.ADD }); }
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); }
private static void createSitelinksFeed(AdWordsUser user, SitelinksDataHolder sitelinksData, string feedName) { // Get the FeedService. FeedService feedService = (FeedService)user.GetService(AdWordsService.v201702.FeedService); // Create attributes. FeedAttribute textAttribute = new FeedAttribute(); textAttribute.type = FeedAttributeType.STRING; textAttribute.name = "Link Text"; FeedAttribute finalUrlAttribute = new FeedAttribute(); finalUrlAttribute.type = FeedAttributeType.URL_LIST; finalUrlAttribute.name = "Link Final URLs"; FeedAttribute line2Attribute = new FeedAttribute(); line2Attribute.type = FeedAttributeType.STRING; line2Attribute.name = "Line 2"; FeedAttribute line3Attribute = new FeedAttribute(); line3Attribute.type = FeedAttributeType.STRING; line3Attribute.name = "Line 3"; // Create the feed. Feed sitelinksFeed = new Feed(); sitelinksFeed.name = feedName; sitelinksFeed.attributes = new FeedAttribute[] { textAttribute, finalUrlAttribute, line2Attribute, line3Attribute }; sitelinksFeed.origin = FeedOrigin.USER; // Create operation. FeedOperation operation = new FeedOperation(); operation.operand = sitelinksFeed; operation.@operator = Operator.ADD; // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation }); Feed savedFeed = result.value[0]; sitelinksData.FeedId = savedFeed.id; FeedAttribute[] savedAttributes = savedFeed.attributes; sitelinksData.LinkTextFeedAttributeId = savedAttributes[0].id; sitelinksData.LinkFinalUrlFeedAttributeId = savedAttributes[1].id; sitelinksData.Line2FeedAttributeId = savedAttributes[2].id; sitelinksData.Line3FeedAttributeId = savedAttributes[3].id; Console.WriteLine("Feed with name {0} and ID {1} with linkTextAttributeId {2}, " + "linkFinalUrlAttributeId {3}, line2AttributeId {4} and line3AttributeId {5} " + "was created.", savedFeed.name, savedFeed.id, savedAttributes[0].id, savedAttributes[1].id, savedAttributes[2].id, savedAttributes[3].id); }
private static FeedItemOperation newSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, String text, String finalUrl, string line2, string line3, long?locationId) { // 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 }; FeedItemAttributeValue line2AttributeValue = new FeedItemAttributeValue(); line2AttributeValue.feedAttributeId = sitelinksData.Line2FeedAttributeId; line2AttributeValue.stringValue = line2; FeedItemAttributeValue line3AttributeValue = new FeedItemAttributeValue(); line3AttributeValue.feedAttributeId = sitelinksData.Line3FeedAttributeId; line3AttributeValue.stringValue = line3; // Create the feed item and operation. FeedItem item = new FeedItem(); item.feedId = sitelinksData.FeedId; // OPTIONAL: Use geographical targeting on a feed item. // The IDs can be found in the documentation or retrieved with the // LocationCriterionService. if (locationId != null) { item.geoTargeting = new Location() { id = locationId.Value, }; // OPTIONAL: Restrict targeting only to people physically within the location. item.geoTargetingRestriction = new FeedItemGeoRestriction() { geoRestriction = GeoRestriction.LOCATION_OF_PRESENCE }; } item.attributeValues = new FeedItemAttributeValue[] { linkTextAttributeValue, linkFinalUrlAttributeValue, line2AttributeValue, line3AttributeValue }; FeedItemOperation operation = new FeedItemOperation(); operation.operand = item; operation.@operator = Operator.ADD; return(operation); }
private static void createSitelinksFeedMapping(AdWordsUser user, SitelinksDataHolder sitelinksData) { using (FeedMappingService feedMappingService = (FeedMappingService)user.GetService(AdWordsService.v201806.FeedMappingService)) { // Map the FeedAttributeIds to the fieldId constants. AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping() { feedAttributeId = sitelinksData.LinkTextFeedAttributeId, fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT }; AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping() { feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId, fieldId = PLACEHOLDER_FIELD_SITELINK_FINAL_URL }; AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping() { feedAttributeId = sitelinksData.Line2FeedAttributeId, fieldId = PLACEHOLDER_FIELD_LINE_2_TEXT }; AttributeFieldMapping line3FieldMapping = new AttributeFieldMapping() { feedAttributeId = sitelinksData.Line3FeedAttributeId, fieldId = PLACEHOLDER_FIELD_LINE_3_TEXT }; // Create the FieldMapping and operation. FeedMappingOperation operation = new FeedMappingOperation() { operand = new FeedMapping() { placeholderType = PLACEHOLDER_SITELINKS, feedId = sitelinksData.FeedId, attributeFieldMappings = new AttributeFieldMapping[] { linkTextFieldMapping, linkFinalUrlFieldMapping, line2FieldMapping, line3FieldMapping } }, @operator = Operator.ADD }; // Save the field mapping. FeedMappingReturnValue result = feedMappingService.mutate(new FeedMappingOperation[] { operation }); foreach (FeedMapping savedFeedMapping in result.value) { Console.WriteLine( "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.", savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType, savedFeedMapping.feedId); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign with which sitelinks are associated. /// </param> /// <param name="feedName">Name of the feed to be created.</param> public void Run(AdWordsUser user, long campaignId, string feedName) { SitelinksDataHolder sitelinksData = new SitelinksDataHolder(); createSitelinksFeed(user, sitelinksData, feedName); createSitelinksFeedItems(user, sitelinksData); createSitelinksFeedMapping(user, sitelinksData); createSitelinksCampaignFeed(user, sitelinksData, campaignId); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign with which sitelinks are associated. /// </param> /// <param name="adGroupId">Id of the adgroup to restrict targeting to.</param> /// <param name="feedName">Name of the feed to be created.</param> public void Run(AdWordsUser user, long campaignId, string feedName, long?adGroupId) { SitelinksDataHolder sitelinksData = new SitelinksDataHolder(); CreateSitelinksFeed(user, sitelinksData, feedName); CreateSitelinksFeedItems(user, sitelinksData); createSitelinksFeedMapping(user, sitelinksData); CreateSitelinksCampaignFeed(user, sitelinksData, campaignId); RestrictFeedItemToAdGroup(user, sitelinksData, adGroupId); }
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); } } }
private static void CreateSitelinksFeedItems(AdWordsUser user, SitelinksDataHolder siteLinksData) { using (FeedItemService feedItemService = (FeedItemService)user.GetService(AdWordsService.v201809.FeedItemService)) { // Create operations to add FeedItems. FeedItemOperation home = NewSitelinkFeedItemAddOperation(siteLinksData, "Home", "http://www.example.com", "Home line 2", "Home line 3"); FeedItemOperation stores = NewSitelinkFeedItemAddOperation(siteLinksData, "Stores", "http://www.example.com/stores", "Stores line 2", "Stores line 3"); FeedItemOperation onSale = NewSitelinkFeedItemAddOperation(siteLinksData, "On Sale", "http://www.example.com/sale", "On Sale line 2", "On Sale line 3"); FeedItemOperation support = NewSitelinkFeedItemAddOperation(siteLinksData, "Support", "http://www.example.com/support", "Support line 2", "Support line 3"); FeedItemOperation products = NewSitelinkFeedItemAddOperation(siteLinksData, "Products", "http://www.example.com/prods", "Products line 2", "Products line 3"); // This site link is using geographical targeting to use LOCATION_OF_PRESENCE. FeedItemOperation aboutUs = NewSitelinkFeedItemAddOperation(siteLinksData, "About Us", "http://www.example.com/about", "About Us line 2", "About Us line 3", true); FeedItemOperation[] operations = new FeedItemOperation[] { home, stores, onSale, support, products, aboutUs }; FeedItemReturnValue result = feedItemService.mutate(operations); foreach (FeedItem item in result.value) { Console.WriteLine("FeedItem with feedItemId {0} was added.", item.feedItemId); siteLinksData.FeedItemIds.Add(item.feedItemId); } // Target the "aboutUs" sitelink to geographically target California. // See https://developers.google.com/adwords/api/docs/appendix/geotargeting for // location criteria for supported locations. RestrictFeedItemToGeoTarget(user, result.value[5], 21137); } }
private static void createSitelinksFeedItems(AdWordsUser user, SitelinksDataHolder siteLinksData) { using (FeedItemService feedItemService = (FeedItemService)user.GetService(AdWordsService.v201802.FeedItemService)) { // Create operations to add FeedItems. FeedItemOperation home = newSitelinkFeedItemAddOperation(siteLinksData, "Home", "http://www.example.com", "Home line 2", "Home line 3"); FeedItemOperation stores = newSitelinkFeedItemAddOperation(siteLinksData, "Stores", "http://www.example.com/stores", "Stores line 2", "Stores line 3"); FeedItemOperation onSale = newSitelinkFeedItemAddOperation(siteLinksData, "On Sale", "http://www.example.com/sale", "On Sale line 2", "On Sale line 3"); FeedItemOperation support = newSitelinkFeedItemAddOperation(siteLinksData, "Support", "http://www.example.com/support", "Support line 2", "Support line 3"); FeedItemOperation products = newSitelinkFeedItemAddOperation(siteLinksData, "Products", "http://www.example.com/prods", "Products line 2", "Products line 3"); // This site link is using geographical targeting by specifying the // criterion ID for California. FeedItemOperation aboutUs = newSitelinkFeedItemAddOperation(siteLinksData, "About Us", "http://www.example.com/about", "About Us line 2", "About Us line 3", 21137); FeedItemOperation[] operations = new FeedItemOperation[] { home, stores, onSale, support, products, aboutUs }; FeedItemReturnValue result = feedItemService.mutate(operations); foreach (FeedItem item in result.value) { Console.WriteLine("FeedItem with feedItemId {0} was added.", item.feedItemId); siteLinksData.FeedItemIds.Add(item.feedItemId); } } }
private static void createSitelinksFeedItems( AdWordsUser user, SitelinksDataHolder siteLinksData) { // Get the FeedItemService. FeedItemService feedItemService = (FeedItemService)user.GetService(AdWordsService.v201502.FeedItemService); // Create operations to add FeedItems. FeedItemOperation home = newSitelinkFeedItemAddOperation(siteLinksData, "Home", "http://www.example.com"); FeedItemOperation stores = newSitelinkFeedItemAddOperation(siteLinksData, "Stores", "http://www.example.com/stores"); FeedItemOperation onSale = newSitelinkFeedItemAddOperation(siteLinksData, "On Sale", "http://www.example.com/sale"); FeedItemOperation support = newSitelinkFeedItemAddOperation(siteLinksData, "Support", "http://www.example.com/support"); FeedItemOperation products = newSitelinkFeedItemAddOperation(siteLinksData, "Products", "http://www.example.com/prods"); FeedItemOperation aboutUs = newSitelinkFeedItemAddOperation(siteLinksData, "About Us", "http://www.example.com/about"); FeedItemOperation[] operations = new FeedItemOperation[] { home, stores, onSale, support, products, aboutUs }; FeedItemReturnValue result = feedItemService.mutate(operations); foreach (FeedItem item in result.value) { Console.WriteLine("FeedItem with feedItemId {0} was added.", item.feedItemId); siteLinksData.FeedItemIds.Add(item.feedItemId); } }
private static void createSitelinksFeedMapping( AdWordsUser user, SitelinksDataHolder sitelinksData) { // Get the FeedItemService. FeedMappingService feedMappingService = (FeedMappingService) user.GetService(AdWordsService.v201502.FeedMappingService); // Map the FeedAttributeIds to the fieldId constants. AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping(); linkTextFieldMapping.feedAttributeId = sitelinksData.LinkTextFeedAttributeId; linkTextFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT; AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping(); linkFinalUrlFieldMapping.feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId; linkFinalUrlFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_FINAL_URL; // Create the FieldMapping and operation. FeedMapping feedMapping = new FeedMapping(); feedMapping.placeholderType = PLACEHOLDER_SITELINKS; feedMapping.feedId = sitelinksData.FeedId; feedMapping.attributeFieldMappings = new AttributeFieldMapping[] {linkTextFieldMapping, linkFinalUrlFieldMapping}; FeedMappingOperation operation = new FeedMappingOperation(); operation.operand = feedMapping; operation.@operator = Operator.ADD; // Save the field mapping. FeedMappingReturnValue result = feedMappingService.mutate(new FeedMappingOperation[] {operation}); foreach (FeedMapping savedFeedMapping in result.value) { Console.WriteLine( "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.", savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType, savedFeedMapping.feedId); } }
private static void createSitelinksCampaignFeed(AdWordsUser user, SitelinksDataHolder sitelinksData, long campaignId) { // Get the CampaignFeedService. CampaignFeedService campaignFeedService = (CampaignFeedService)user.GetService(AdWordsService.v201502.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.FeedItemIds) { 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.FeedId; 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); } }
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); } }
private static FeedItemOperation newSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, String text, String finalUrl, long? locationId) { // 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; // OPTIONAL: Use geographical targeting on a feed item. // The IDs can be found in the documentation or retrieved with the // LocationCriterionService. if (locationId != null) { item.geoTargeting = new Location() { id = locationId.Value }; } item.attributeValues = new FeedItemAttributeValue[] {linkTextAttributeValue, linkFinalUrlAttributeValue}; FeedItemOperation operation = new FeedItemOperation(); operation.operand = item; operation.@operator = Operator.ADD; return operation; }
private static FeedItemOperation newSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, String text, String finalUrl, string line2, string line3) { return(newSitelinkFeedItemAddOperation(sitelinksData, text, finalUrl, line2, line3, null)); }
private static void createSitelinksFeedItems( AdWordsUser user, SitelinksDataHolder siteLinksData) { // Get the FeedItemService. FeedItemService feedItemService = (FeedItemService) user.GetService(AdWordsService.v201502.FeedItemService); // Create operations to add FeedItems. FeedItemOperation home = newSitelinkFeedItemAddOperation(siteLinksData, "Home", "http://www.example.com"); FeedItemOperation stores = newSitelinkFeedItemAddOperation(siteLinksData, "Stores", "http://www.example.com/stores"); FeedItemOperation onSale = newSitelinkFeedItemAddOperation(siteLinksData, "On Sale", "http://www.example.com/sale"); FeedItemOperation support = newSitelinkFeedItemAddOperation(siteLinksData, "Support", "http://www.example.com/support"); FeedItemOperation products = newSitelinkFeedItemAddOperation(siteLinksData, "Products", "http://www.example.com/prods"); FeedItemOperation aboutUs = newSitelinkFeedItemAddOperation(siteLinksData, "About Us", "http://www.example.com/about"); FeedItemOperation[] operations = new FeedItemOperation[] {home, stores, onSale, support, products, aboutUs}; FeedItemReturnValue result = feedItemService.mutate(operations); foreach (FeedItem item in result.value) { Console.WriteLine("FeedItem with feedItemId {0} was added.", item.feedItemId); siteLinksData.FeedItemIds.Add(item.feedItemId); } }
private static void createSitelinksFeed(AdWordsUser user, SitelinksDataHolder sitelinksData, string feedName) { // Get the FeedService. FeedService feedService = (FeedService) user.GetService(AdWordsService.v201502.FeedService); // Create attributes. FeedAttribute textAttribute = new FeedAttribute(); textAttribute.type = FeedAttributeType.STRING; textAttribute.name = "Link Text"; FeedAttribute finalUrlAttribute = new FeedAttribute(); finalUrlAttribute.type = FeedAttributeType.URL_LIST; finalUrlAttribute.name = "Link URL"; // Create the feed. Feed sitelinksFeed = new Feed(); sitelinksFeed.name = feedName; sitelinksFeed.attributes = new FeedAttribute[] {textAttribute, finalUrlAttribute}; sitelinksFeed.origin = FeedOrigin.USER; // Create operation. FeedOperation operation = new FeedOperation(); operation.operand = sitelinksFeed; operation.@operator = Operator.ADD; // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] {operation}); Feed savedFeed = result.value[0]; sitelinksData.FeedId = savedFeed.id; FeedAttribute[] savedAttributes = savedFeed.attributes; sitelinksData.LinkTextFeedAttributeId = savedAttributes[0].id; sitelinksData.LinkFinalUrlFeedAttributeId = savedAttributes[1].id; Console.WriteLine("Feed with name {0} and ID {1} with linkTextAttributeId {2}" + " and linkFinalUrlAttributeId {3} was created.", savedFeed.name, savedFeed.id, savedAttributes[0].id, savedAttributes[1].id); }
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; }
private static FeedItemOperation newSitelinkFeedItemAddOperation( SitelinksDataHolder sitelinksData, String text, String finalUrl) { return newSitelinkFeedItemAddOperation(sitelinksData, text, finalUrl, null); }