use of com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method createSiteLinksCampaignFeed.
private static void createSiteLinksCampaignFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, Long campaignId) throws RemoteException {
// Get the CampaignFeedService.
CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
// Construct a matching function that associates the sitelink feed items to the campaign, and
// sets the device preference to mobile. See the matching function guide at
// https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
// for more details.
String matchingFunctionString = String.format("AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, 'Mobile') )", Joiner.on(',').join(siteLinksData.siteLinkFeedItemIds));
CampaignFeed campaignFeed = new CampaignFeed();
campaignFeed.setFeedId(siteLinksData.siteLinksFeedId);
campaignFeed.setCampaignId(campaignId);
Function matchingFunction = new Function();
matchingFunction.setFunctionString(matchingFunctionString);
campaignFeed.setMatchingFunction(matchingFunction);
// Specifying placeholder types on the CampaignFeed allows the same feed
// to be used for different placeholders in different Campaigns.
campaignFeed.setPlaceholderTypes(new int[] { PLACEHOLDER_SITELINKS });
CampaignFeedOperation operation = new CampaignFeedOperation();
operation.setOperand(campaignFeed);
operation.setOperator(Operator.ADD);
CampaignFeedReturnValue result = campaignFeedService.mutate(new CampaignFeedOperation[] { operation });
for (CampaignFeed savedCampaignFeed : result.getValue()) {
System.out.printf("Campaign with ID %d was associated with feed with ID %d.%n", savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
}
}
Aggregations