private static void createSiteLinksFeedItems( AdWordsServices adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData) throws Exception { // Get the FeedItemService. FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class); // Create operations to add FeedItems. FeedItemOperation home = newSiteLinkFeedItemAddOperation( siteLinksData, "Home", "http://www.example.com", "Home line 1", "Home line 2"); FeedItemOperation stores = newSiteLinkFeedItemAddOperation( siteLinksData, "Stores", "http://www.example.com/stores", "Stores line 1", "Stores line 2"); FeedItemOperation onSale = newSiteLinkFeedItemAddOperation( siteLinksData, "On Sale", "http://www.example.com/sale", "On Sale line 1", "On Sale line 2"); FeedItemOperation support = newSiteLinkFeedItemAddOperation( siteLinksData, "Support", "http://www.example.com/support", "Support line 1", "Support line 2"); FeedItemOperation products = newSiteLinkFeedItemAddOperation( siteLinksData, "Products", "http://www.example.com/prods", "Products line 1", "Products line 2"); FeedItemOperation aboutUs = newSiteLinkFeedItemAddOperation( siteLinksData, "About Us", "http://www.example.com/about", "About Us line 1", "About Us line 2"); FeedItemOperation[] operations = new FeedItemOperation[] {home, stores, onSale, support, products, aboutUs}; FeedItemReturnValue result = feedItemService.mutate(operations); for (FeedItem item : result.getValue()) { System.out.printf("FeedItem with feedItemId %d was added.\n", item.getFeedItemId()); siteLinksData.siteLinkFeedItemIds.add(item.getFeedItemId()); } }
private static FeedItemOperation newSiteLinkFeedItemAddOperation( SiteLinksDataHolder siteLinksData, String text, String finalUrl, String line1, String line2) { // Create the FeedItemAttributeValues for our text values. FeedItemAttributeValue linkTextAttributeValue = new FeedItemAttributeValue(); linkTextAttributeValue.setFeedAttributeId(siteLinksData.linkTextFeedAttributeId); linkTextAttributeValue.setStringValue(text); FeedItemAttributeValue linkFinalUrlAttributeValue = new FeedItemAttributeValue(); linkFinalUrlAttributeValue.setFeedAttributeId(siteLinksData.linkFinalUrlFeedAttributeId); linkFinalUrlAttributeValue.setStringValues(new String[] {finalUrl}); FeedItemAttributeValue line1TextAttributeValue = new FeedItemAttributeValue(); line1TextAttributeValue.setFeedAttributeId(siteLinksData.line1FeedAttributeId); line1TextAttributeValue.setStringValue(line1); FeedItemAttributeValue line2TextAttributeValue = new FeedItemAttributeValue(); line2TextAttributeValue.setFeedAttributeId(siteLinksData.line2FeedAttributeId); line2TextAttributeValue.setStringValue(line2); // Create the feed item and operation. FeedItem item = new FeedItem(); item.setFeedId(siteLinksData.siteLinksFeedId); item.setAttributeValues( new FeedItemAttributeValue[] { linkTextAttributeValue, linkFinalUrlAttributeValue, line1TextAttributeValue, line2TextAttributeValue }); // Optional: use item.setStartTime() and item.setEndTime() to specify the // time period for the feed to deliver. The example below will make the feed // start now and stop in one month. // Make sure you specify the DateTime in the customer's time zone. You can // retrieve this from customer.getDateTimeZone(). // item.setStartTime(new DateTime(customerTimeZone).toString("yyyyMMdd HHmmss")); // item.setEndTime(new DateTime(customerTimeZone).plusMonths(1).toString("yyyyMMdd HHmmss")); // Optional: use item.setScheduling() to specify time and days of the week for feed to deliver. FeedItemOperation operation = new FeedItemOperation(); operation.setOperand(item); operation.setOperator(Operator.ADD); return operation; }