use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method getSiteLinksFromFeed.
/**
* Gets the site links from a feed.
*
* @return a map of feed item ID to SiteLinkFromFeed
*/
private static Map<Long, SiteLinkFromFeed> getSiteLinksFromFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed) throws RemoteException {
// Retrieve the feed's attribute mapping.
Multimap<Long, Integer> feedMappings = getFeedMapping(adWordsServices, session, feed, PLACEHOLDER_SITELINKS);
Map<Long, SiteLinkFromFeed> feedItems = Maps.newHashMap();
for (FeedItem feedItem : getFeedItems(adWordsServices, session, feed)) {
SiteLinkFromFeed siteLinkFromFeed = new SiteLinkFromFeed();
for (FeedItemAttributeValue attributeValue : feedItem.getAttributeValues()) {
// Skip this attribute if it hasn't been mapped to a field.
if (!feedMappings.containsKey(attributeValue.getFeedAttributeId())) {
continue;
}
for (Integer fieldId : feedMappings.get(attributeValue.getFeedAttributeId())) {
switch(fieldId) {
case PLACEHOLDER_FIELD_SITELINK_LINK_TEXT:
siteLinkFromFeed.text = attributeValue.getStringValue();
break;
case PLACEHOLDER_FIELD_SITELINK_URL:
siteLinkFromFeed.url = attributeValue.getStringValue();
break;
case PLACEHOLDER_FIELD_FINAL_URLS:
siteLinkFromFeed.finalUrls = attributeValue.getStringValues();
break;
case PLACEHOLDER_FIELD_FINAL_MOBILE_URLS:
siteLinkFromFeed.finalMobileUrls = attributeValue.getStringValues();
break;
case PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE:
siteLinkFromFeed.trackingUrlTemplate = attributeValue.getStringValue();
break;
case PLACEHOLDER_FIELD_LINE_2_TEXT:
siteLinkFromFeed.line2 = attributeValue.getStringValue();
break;
case PLACEHOLDER_FIELD_LINE_3_TEXT:
siteLinkFromFeed.line3 = attributeValue.getStringValue();
break;
default:
// Ignore attributes that do not map to a predefined placeholder field.
break;
}
}
}
feedItems.put(feedItem.getFeedItemId(), siteLinkFromFeed);
}
return feedItems;
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue 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.FeedItemAttributeValue 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.FeedItemAttributeValue 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