use of com.google.api.ads.adwords.axis.v201809.cm.UrlList in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method createExtensionSetting.
/**
* Creates the extension setting for a list of feed items.
*
* @param adWordsServices the AdWordsServices
* @param session the AdWordsSession
* @param feedItems the list of all feed items
* @param campaignFeed the original campaign feed
* @param feedItemIds IDs of the feed items for which extension settings should be created
* @param platformRestrictions the platform restrictions for the new campaign extension setting
*/
private static void createExtensionSetting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Map<Long, SiteLinkFromFeed> feedItems, CampaignFeed campaignFeed, Set<Long> feedItemIds, ExtensionSettingPlatform platformRestrictions) throws RemoteException {
// Get the CampaignExtensionSettingService.
CampaignExtensionSettingServiceInterface campaignExtensionSettingService = adWordsServices.get(session, CampaignExtensionSettingServiceInterface.class);
CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();
campaignExtensionSetting.setCampaignId(campaignFeed.getCampaignId());
campaignExtensionSetting.setExtensionType(FeedType.SITELINK);
ExtensionSetting extensionSetting = new ExtensionSetting();
List<ExtensionFeedItem> extensionFeedItems = new ArrayList<>();
for (Long feedItemId : feedItemIds) {
SiteLinkFromFeed siteLinkFromFeed = feedItems.get(feedItemId);
SitelinkFeedItem siteLinkFeedItem = new SitelinkFeedItem();
siteLinkFeedItem.setSitelinkText(siteLinkFromFeed.text);
if (siteLinkFromFeed.finalUrls != null && siteLinkFromFeed.finalUrls.length > 0) {
siteLinkFeedItem.setSitelinkFinalUrls(new UrlList(siteLinkFromFeed.finalUrls));
if (siteLinkFromFeed.finalMobileUrls != null && siteLinkFromFeed.finalMobileUrls.length > 0) {
siteLinkFeedItem.setSitelinkFinalMobileUrls(new UrlList(siteLinkFromFeed.finalMobileUrls));
}
siteLinkFeedItem.setSitelinkTrackingUrlTemplate(siteLinkFromFeed.trackingUrlTemplate);
} else {
siteLinkFeedItem.setSitelinkUrl(siteLinkFromFeed.url);
}
siteLinkFeedItem.setSitelinkLine2(siteLinkFromFeed.line2);
siteLinkFeedItem.setSitelinkLine3(siteLinkFromFeed.line3);
extensionFeedItems.add(siteLinkFeedItem);
}
extensionSetting.setExtensions(extensionFeedItems.toArray(new ExtensionFeedItem[extensionFeedItems.size()]));
extensionSetting.setPlatformRestrictions(platformRestrictions);
campaignExtensionSetting.setExtensionSetting(extensionSetting);
CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation();
operation.setOperand(campaignExtensionSetting);
operation.setOperator(Operator.ADD);
campaignExtensionSettingService.mutate(new CampaignExtensionSettingOperation[] { operation });
}
use of com.google.api.ads.adwords.axis.v201809.cm.UrlList in project googleads-java-lib by googleads.
the class AddSiteLinks method createSiteLinkFeedItem.
/**
* Creates a new {@link SitelinkFeedItem} with the specified attributes.
*
* @param sitelinkText the text for the sitelink
* @param sitelinkUrl the URL for the sitelink
* @return a new SitelinkFeedItem
*/
private static SitelinkFeedItem createSiteLinkFeedItem(String sitelinkText, String sitelinkUrl) {
SitelinkFeedItem sitelinkFeedItem = new SitelinkFeedItem();
sitelinkFeedItem.setSitelinkText(sitelinkText);
sitelinkFeedItem.setSitelinkFinalUrls(new UrlList(new String[] { sitelinkUrl }));
return sitelinkFeedItem;
}
use of com.google.api.ads.adwords.axis.v201809.cm.UrlList in project googleads-java-lib by googleads.
the class AddPrices method createPriceTableRow.
/**
* Creates a new {@link PriceTableRow} with the specified attributes.
*
* @param header the header for the row
* @param description the description for the row
* @param finalUrl the final URL for the row
* @param finalMobileUrl the final mobile URL for the row, or null if this field should not be set
* @param priceInMicros the price for the row, in micros
* @param currencyCode the currency for the row
* @param priceUnit the price unit for the row
* @return a new {@link PriceTableRow}
*/
private static PriceTableRow createPriceTableRow(String header, String description, String finalUrl, String finalMobileUrl, long priceInMicros, String currencyCode, PriceExtensionPriceUnit priceUnit) {
PriceTableRow priceTableRow = new PriceTableRow();
priceTableRow.setHeader(header);
priceTableRow.setDescription(description);
UrlList finalUrls = new UrlList();
finalUrls.setUrls(new String[] { finalUrl });
priceTableRow.setFinalUrls(finalUrls);
if (finalMobileUrl != null) {
UrlList finalMobileUrls = new UrlList();
finalMobileUrls.setUrls(new String[] { finalMobileUrl });
priceTableRow.setFinalMobileUrls(finalMobileUrls);
}
MoneyWithCurrency price = new MoneyWithCurrency();
Money priceMoney = new Money();
price.setCurrencyCode(currencyCode);
priceMoney.setMicroAmount(priceInMicros);
price.setMoney(priceMoney);
priceTableRow.setPrice(price);
priceTableRow.setPriceUnit(priceUnit);
return priceTableRow;
}
use of com.google.api.ads.adwords.axis.v201809.cm.UrlList in project googleads-java-lib by googleads.
the class AddKeywords method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group where the keywords will be created.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws UnsupportedEncodingException if encoding the final URL failed.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException, UnsupportedEncodingException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create keywords.
Keyword keyword1 = new Keyword();
keyword1.setText("mars cruise");
keyword1.setMatchType(KeywordMatchType.BROAD);
Keyword keyword2 = new Keyword();
keyword2.setText("space hotel");
keyword2.setMatchType(KeywordMatchType.EXACT);
// Create biddable ad group criterion.
BiddableAdGroupCriterion keywordBiddableAdGroupCriterion1 = new BiddableAdGroupCriterion();
keywordBiddableAdGroupCriterion1.setAdGroupId(adGroupId);
keywordBiddableAdGroupCriterion1.setCriterion(keyword1);
// You can optionally provide these field(s).
keywordBiddableAdGroupCriterion1.setUserStatus(UserStatus.PAUSED);
String encodedFinalUrl = String.format("http://example.com/mars/cruise/?kw=%s", URLEncoder.encode(keyword1.getText(), UTF_8.name()));
keywordBiddableAdGroupCriterion1.setFinalUrls(new UrlList(new String[] { encodedFinalUrl }));
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpcBid bid = new CpcBid();
bid.setBid(new Money(null, 10000000L));
biddingStrategyConfiguration.setBids(new Bids[] { bid });
keywordBiddableAdGroupCriterion1.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
NegativeAdGroupCriterion keywordNegativeAdGroupCriterion2 = new NegativeAdGroupCriterion();
keywordNegativeAdGroupCriterion2.setAdGroupId(adGroupId);
keywordNegativeAdGroupCriterion2.setCriterion(keyword2);
// Create operations.
AdGroupCriterionOperation keywordAdGroupCriterionOperation1 = new AdGroupCriterionOperation();
keywordAdGroupCriterionOperation1.setOperand(keywordBiddableAdGroupCriterion1);
keywordAdGroupCriterionOperation1.setOperator(Operator.ADD);
AdGroupCriterionOperation keywordAdGroupCriterionOperation2 = new AdGroupCriterionOperation();
keywordAdGroupCriterionOperation2.setOperand(keywordNegativeAdGroupCriterion2);
keywordAdGroupCriterionOperation2.setOperator(Operator.ADD);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { keywordAdGroupCriterionOperation1, keywordAdGroupCriterionOperation2 };
// Add keywords.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display results.
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
System.out.printf("Keyword ad group criterion with ad group ID %d, criterion ID %d, " + "text '%s', and match type '%s' was added.%n", adGroupCriterionResult.getAdGroupId(), adGroupCriterionResult.getCriterion().getId(), ((Keyword) adGroupCriterionResult.getCriterion()).getText(), ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType());
}
}
Aggregations