Search in sources :

Example 1 with PriceTableRow

use of com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow in project googleads-java-lib by googleads.

the class AddPrices method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where price feed items will be added.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId) throws ApiException, RemoteException {
    // Get the CustomerExtensionSettingService.
    CustomerExtensionSettingServiceInterface customerExtensionSettingService = adWordsServices.get(session, CustomerExtensionSettingServiceInterface.class);
    // Create the price extension feed item.
    PriceFeedItem priceFeedItem = new PriceFeedItem();
    priceFeedItem.setPriceExtensionType(PriceExtensionType.SERVICES);
    // Price qualifier is optional.
    priceFeedItem.setPriceQualifier(PriceExtensionPriceQualifier.FROM);
    priceFeedItem.setTrackingUrlTemplate("http://tracker.example.com/?u={lpurl}");
    priceFeedItem.setLanguage("en");
    FeedItemCampaignTargeting campaignTargeting = new FeedItemCampaignTargeting();
    campaignTargeting.setTargetingCampaignId(campaignId);
    priceFeedItem.setCampaignTargeting(campaignTargeting);
    priceFeedItem.setScheduling(new FeedItemScheduling(new FeedItemSchedule[] { new FeedItemSchedule(DayOfWeek.SUNDAY, 10, MinuteOfHour.ZERO, 18, MinuteOfHour.ZERO), new FeedItemSchedule(DayOfWeek.SATURDAY, 10, MinuteOfHour.ZERO, 22, MinuteOfHour.ZERO) }));
    // To create a price extension, at least three table rows are needed.
    List<PriceTableRow> priceTableRows = new ArrayList<>();
    String currencyCode = "USD";
    priceTableRows.add(createPriceTableRow("Scrubs", "Body Scrub, Salt Scrub", "http://www.example.com/scrubs", "http://m.example.com/scrubs", 60000000, currencyCode, PriceExtensionPriceUnit.PER_HOUR));
    priceTableRows.add(createPriceTableRow("Hair Cuts", "Once a month", "http://www.example.com/haircuts", "http://m.example.com/haircuts", 75000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
    priceTableRows.add(createPriceTableRow("Skin Care Package", "Four times a month", "http://www.example.com/skincarepackage", null, 250000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
    priceFeedItem.setTableRows(priceTableRows.toArray(new PriceTableRow[priceTableRows.size()]));
    // Create your campaign extension settings. This associates the sitelinks
    // to your campaign.
    CustomerExtensionSetting customerExtensionSetting = new CustomerExtensionSetting();
    customerExtensionSetting.setExtensionType(FeedType.PRICE);
    ExtensionSetting extensionSetting = new ExtensionSetting();
    extensionSetting.setExtensions(new ExtensionFeedItem[] { priceFeedItem });
    customerExtensionSetting.setExtensionSetting(extensionSetting);
    CustomerExtensionSettingOperation operation = new CustomerExtensionSettingOperation();
    operation.setOperand(customerExtensionSetting);
    operation.setOperator(Operator.ADD);
    // Add the extensions.
    CustomerExtensionSettingReturnValue returnValue = customerExtensionSettingService.mutate(new CustomerExtensionSettingOperation[] { operation });
    if (returnValue.getValue() != null && returnValue.getValue().length > 0) {
        CustomerExtensionSetting newExtensionSetting = returnValue.getValue(0);
        System.out.printf("Extension setting with type '%s' was added.%n", newExtensionSetting.getExtensionType().getValue());
    } else {
        System.out.println("No extension settings were created.");
    }
}
Also used : CustomerExtensionSettingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingServiceInterface) ExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting) CustomerExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting) CustomerExtensionSettingOperation(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingOperation) FeedItemSchedule(com.google.api.ads.adwords.axis.v201809.cm.FeedItemSchedule) ArrayList(java.util.ArrayList) PriceTableRow(com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow) FeedItemCampaignTargeting(com.google.api.ads.adwords.axis.v201809.cm.FeedItemCampaignTargeting) FeedItemScheduling(com.google.api.ads.adwords.axis.v201809.cm.FeedItemScheduling) PriceFeedItem(com.google.api.ads.adwords.axis.v201809.cm.PriceFeedItem) CustomerExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting) CustomerExtensionSettingReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingReturnValue)

Example 2 with PriceTableRow

use of com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow 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;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) MoneyWithCurrency(com.google.api.ads.adwords.axis.v201809.cm.MoneyWithCurrency) PriceTableRow(com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow) UrlList(com.google.api.ads.adwords.axis.v201809.cm.UrlList)

Aggregations

PriceTableRow (com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow)2 CustomerExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting)1 CustomerExtensionSettingOperation (com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingOperation)1 CustomerExtensionSettingReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingReturnValue)1 CustomerExtensionSettingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingServiceInterface)1 ExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting)1 FeedItemCampaignTargeting (com.google.api.ads.adwords.axis.v201809.cm.FeedItemCampaignTargeting)1 FeedItemSchedule (com.google.api.ads.adwords.axis.v201809.cm.FeedItemSchedule)1 FeedItemScheduling (com.google.api.ads.adwords.axis.v201809.cm.FeedItemScheduling)1 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)1 MoneyWithCurrency (com.google.api.ads.adwords.axis.v201809.cm.MoneyWithCurrency)1 PriceFeedItem (com.google.api.ads.adwords.axis.v201809.cm.PriceFeedItem)1 UrlList (com.google.api.ads.adwords.axis.v201809.cm.UrlList)1 ArrayList (java.util.ArrayList)1