use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method createSiteLinksFeedItems.
private static void createSiteLinksFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData) throws RemoteException {
// 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 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);
for (FeedItem item : result.getValue()) {
System.out.printf("FeedItem with feedItemId %d was added.%n", item.getFeedItemId());
siteLinksData.siteLinkFeedItemIds.add(item.getFeedItemId());
}
// 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(adWordsServices, session, result.getValue(5), 21137L);
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface in project googleads-java-lib by googleads.
the class AddAdCustomizer method createCustomizerFeedItems.
/**
* Creates FeedItems with the values to use in ad customizations for each ad group in
* <code>adGroupIds</code>.
*/
private static void createCustomizerFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, AdCustomizerFeed adCustomizerFeed) throws RemoteException {
// Get the FeedItemService.
FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
List<FeedItemOperation> feedItemOperations = new ArrayList<>();
DateTime now = DateTime.now();
DateTime marsDate = new DateTime(now.getYear(), now.getMonthOfYear(), 1, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Mars", "$1234.56", marsDate.toString("yyyyMMdd HHmmss"), adCustomizerFeed));
DateTime venusDate = new DateTime(now.getYear(), now.getMonthOfYear(), 15, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Venus", "$1450.00", venusDate.toString("yyyyMMdd HHmmss"), adCustomizerFeed));
FeedItemReturnValue feedItemReturnValue = feedItemService.mutate(feedItemOperations.toArray(new FeedItemOperation[feedItemOperations.size()]));
for (FeedItem addedFeedItem : feedItemReturnValue.getValue()) {
System.out.printf("Added feed item with ID %d.%n", addedFeedItem.getFeedItemId());
}
// Add feed item targeting to restrict the feed item to specific ad groups.
restrictFeedItemToAdGroup(adWordsServices, session, feedItemReturnValue.getValue(0), adGroupIds.get(0));
restrictFeedItemToAdGroup(adWordsServices, session, feedItemReturnValue.getValue(1), adGroupIds.get(1));
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createFeedItems.
/**
* Creates the page URLs in the DSA page feed.
*/
private static void createFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, DSAFeedDetails feedDetails, String labelName) throws RemoteException {
// Get the FeedItemService.
FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
// Create operations to add FeedItems.
FeedItemOperation[] operations = new FeedItemOperation[] { createDsaUrlAddOperation(feedDetails, "http://www.example.com/discounts/rental-cars", labelName), createDsaUrlAddOperation(feedDetails, "http://www.example.com/discounts/hotel-deals", labelName), createDsaUrlAddOperation(feedDetails, "http://www.example.com/discounts/flight-deals", labelName) };
FeedItemReturnValue result = feedItemService.mutate(operations);
for (FeedItem item : result.getValue()) {
System.out.printf("Feed item with feed item ID %d was added.%n", item.getFeedItemId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method getFeedItems.
/**
* Returns the feed items for a feed.
*/
private static List<FeedItem> getFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed) throws RemoteException {
// Get the FeedItemService.
FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
String query = String.format("SELECT FeedItemId, AttributeValues WHERE Status = 'ENABLED' AND FeedId = %d", feed.getId());
List<FeedItem> feedItems = new ArrayList<>();
int offset = 0;
FeedItemPage feedItemPage;
do {
String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
feedItemPage = feedItemService.query(pageQuery);
if (feedItemPage.getEntries() != null) {
feedItems.addAll(Arrays.asList(feedItemPage.getEntries()));
}
offset += PAGE_SIZE;
} while (offset < feedItemPage.getTotalNumEntries());
return feedItems;
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method deleteOldFeedItems.
/**
* Deletes the old feed items for which extension settings have been created.
*/
private static void deleteOldFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, Set<Long> feedItemIds, Feed feed) throws RemoteException {
// Get the FeedItemService.
FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
if (feedItemIds.isEmpty()) {
return;
}
List<FeedItemOperation> operations = new ArrayList<>();
for (Long feedItemId : feedItemIds) {
FeedItemOperation operation = new FeedItemOperation();
FeedItem feedItem = new FeedItem();
feedItem.setFeedId(feed.getId());
feedItem.setFeedItemId(feedItemId);
operation.setOperand(feedItem);
operation.setOperator(Operator.REMOVE);
operations.add(operation);
}
feedItemService.mutate(operations.toArray(new FeedItemOperation[operations.size()]));
}
Aggregations