use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class AddAdCustomizer method restrictFeedItemToAdGroup.
/**
* Restricts the feed item to an ad group.
*/
private static void restrictFeedItemToAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, FeedItem feedItem, long adGroupId) throws RemoteException {
// Get the FeedItemTargetingService.
FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
FeedItemAdGroupTarget adGroupTarget = new FeedItemAdGroupTarget();
adGroupTarget.setFeedId(feedItem.getFeedId());
adGroupTarget.setFeedItemId(feedItem.getFeedItemId());
adGroupTarget.setAdGroupId(adGroupId);
FeedItemTargetOperation operation = new FeedItemTargetOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(adGroupTarget);
FeedItemTargetReturnValue returnValue = feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation });
FeedItemAdGroupTarget addedAdGroupTarget = (FeedItemAdGroupTarget) returnValue.getValue(0);
System.out.printf("Feed item target for feed ID %d and feed item ID %d " + "was created to restrict serving to ad group ID %d.%n", addedAdGroupTarget.getFeedId(), addedAdGroupTarget.getFeedItemId(), addedAdGroupTarget.getAdGroupId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed 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.Feed 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;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed 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.Feed in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createFeedMapping.
/**
* Creates the feed mapping for the DSA page feeds.
*/
private static void createFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, DSAFeedDetails feedDetails) throws RemoteException {
// Get the FeedMappingService.
FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
// Map the FeedAttributeIds to the fieldId constants.
AttributeFieldMapping urlFieldMapping = new AttributeFieldMapping();
urlFieldMapping.setFeedAttributeId(feedDetails.urlAttributeId);
urlFieldMapping.setFieldId(DSA_PAGE_URLS_FIELD_ID);
AttributeFieldMapping labelFieldMapping = new AttributeFieldMapping();
labelFieldMapping.setFeedAttributeId(feedDetails.labelAttributeId);
labelFieldMapping.setFieldId(DSA_LABEL_FIELD_ID);
// Create the FeedMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setCriterionType(DSA_PAGE_FEED_CRITERION_TYPE);
feedMapping.setFeedId(feedDetails.feedId);
feedMapping.setAttributeFieldMappings(new AttributeFieldMapping[] { urlFieldMapping, labelFieldMapping });
FeedMappingOperation operation = new FeedMappingOperation();
operation.setOperand(feedMapping);
operation.setOperator(Operator.ADD);
// Add the field mapping.
FeedMapping newFeedMapping = feedMappingService.mutate(new FeedMappingOperation[] { operation }).getValue(0);
System.out.printf("Feed mapping with ID %d and criterionType %d was saved for feed with ID %d.%n", newFeedMapping.getFeedMappingId(), newFeedMapping.getCriterionType(), newFeedMapping.getFeedId());
}
Aggregations