Search in sources :

Example 1 with UrlList

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 });
}
Also used : ExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting) CampaignExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting) CampaignExtensionSettingOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingOperation) ExtensionFeedItem(com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem) CampaignExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting) SitelinkFeedItem(com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem) ArrayList(java.util.ArrayList) CampaignExtensionSettingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface) UrlList(com.google.api.ads.adwords.axis.v201809.cm.UrlList)

Example 2 with UrlList

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

Example 3 with UrlList

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;
}
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)

Example 4 with UrlList

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());
    }
}
Also used : AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) UrlList(com.google.api.ads.adwords.axis.v201809.cm.UrlList) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Aggregations

UrlList (com.google.api.ads.adwords.axis.v201809.cm.UrlList)4 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)2 SitelinkFeedItem (com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem)2 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)1 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)1 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)1 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)1 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)1 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)1 CampaignExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting)1 CampaignExtensionSettingOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingOperation)1 CampaignExtensionSettingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface)1 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)1 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)1 ExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting)1 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)1 MoneyWithCurrency (com.google.api.ads.adwords.axis.v201809.cm.MoneyWithCurrency)1 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)1 PriceTableRow (com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow)1 ArrayList (java.util.ArrayList)1