use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation 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.FeedItemOperation in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method newSiteLinkFeedItemAddOperation.
private static FeedItemOperation newSiteLinkFeedItemAddOperation(SiteLinksDataHolder siteLinksData, String text, String finalUrl, String line2, String line3, boolean restrictToLop) {
// 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 line2TextAttributeValue = new FeedItemAttributeValue();
line2TextAttributeValue.setFeedAttributeId(siteLinksData.line2FeedAttributeId);
line2TextAttributeValue.setStringValue(line2);
FeedItemAttributeValue line3TextAttributeValue = new FeedItemAttributeValue();
line3TextAttributeValue.setFeedAttributeId(siteLinksData.line3FeedAttributeId);
line3TextAttributeValue.setStringValue(line3);
// Create the feed item and operation.
FeedItem item = new FeedItem();
item.setFeedId(siteLinksData.siteLinksFeedId);
item.setAttributeValues(new FeedItemAttributeValue[] { linkTextAttributeValue, linkFinalUrlAttributeValue, line2TextAttributeValue, line3TextAttributeValue });
// OPTIONAL: Restrict targeting only to people physically within the location.
if (restrictToLop) {
FeedItemGeoRestriction geoTargetingRestriction = new FeedItemGeoRestriction();
geoTargetingRestriction.setGeoRestriction(GeoRestriction.LOCATION_OF_PRESENCE);
item.setGeoTargetingRestriction(geoTargetingRestriction);
}
// 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;
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation 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.FeedItemOperation in project googleads-java-lib by googleads.
the class AddAdCustomizer method createFeedItemAddOperation.
/**
* Creates a FeedItemOperation that will create a FeedItem with the specified values and ad group
* target when sent to FeedItemService.mutate.
*
* @param name the value for the name attribute of the FeedItem
* @param price the value for the price attribute of the FeedItem
* @param date the value for the date attribute of the FeedItem
* @param adCustomizerFeed the customizer feed
* @return a new FeedItemOperation for adding a FeedItem
*/
private static FeedItemOperation createFeedItemAddOperation(String name, String price, String date, AdCustomizerFeed adCustomizerFeed) {
FeedItem feedItem = new FeedItem();
feedItem.setFeedId(adCustomizerFeed.getFeedId());
List<FeedItemAttributeValue> attributeValues = new ArrayList<>();
// FeedAttributes appear in the same order as they were created - Name, Price, Date.
// See the createCustomizerFeed method for details.
FeedItemAttributeValue nameAttributeValue = new FeedItemAttributeValue();
nameAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(0).getId());
nameAttributeValue.setStringValue(name);
attributeValues.add(nameAttributeValue);
FeedItemAttributeValue priceAttributeValue = new FeedItemAttributeValue();
priceAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(1).getId());
priceAttributeValue.setStringValue(price);
attributeValues.add(priceAttributeValue);
FeedItemAttributeValue dateAttributeValue = new FeedItemAttributeValue();
dateAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(2).getId());
dateAttributeValue.setStringValue(date);
attributeValues.add(dateAttributeValue);
feedItem.setAttributeValues(attributeValues.toArray(new FeedItemAttributeValue[attributeValues.size()]));
FeedItemOperation feedItemOperation = new FeedItemOperation();
feedItemOperation.setOperand(feedItem);
feedItemOperation.setOperator(Operator.ADD);
return feedItemOperation;
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createDsaUrlAddOperation.
/**
* Creates a {@link FeedItemOperation} to add the DSA URL.
*/
private static FeedItemOperation createDsaUrlAddOperation(DSAFeedDetails feedDetails, String url, String labelName) {
// Create the FeedItemAttributeValues for the URL and label.
FeedItemAttributeValue urlAttributeValue = new FeedItemAttributeValue();
urlAttributeValue.setFeedAttributeId(feedDetails.urlAttributeId);
// See https://support.google.com/adwords/answer/7166527 for page feed URL recommendations and
// rules.
urlAttributeValue.setStringValues(new String[] { url });
FeedItemAttributeValue labelAttributeValue = new FeedItemAttributeValue();
labelAttributeValue.setFeedAttributeId(feedDetails.labelAttributeId);
labelAttributeValue.setStringValues(new String[] { labelName });
// Create the feed item and operation.
FeedItem feedItem = new FeedItem();
feedItem.setFeedId(feedDetails.feedId);
feedItem.setAttributeValues(new FeedItemAttributeValue[] { urlAttributeValue, labelAttributeValue });
FeedItemOperation operation = new FeedItemOperation();
operation.setOperand(feedItem);
operation.setOperator(Operator.ADD);
return operation;
}
Aggregations