Search in sources :

Example 1 with ExpandedTextAd

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

the class AddCompleteCampaignsUsingBatchJob method buildAdGroupAdOperations.

private static List<AdGroupAdOperation> buildAdGroupAdOperations(List<AdGroupOperation> adGroupOperations) {
    List<AdGroupAdOperation> operations = new ArrayList<>();
    for (AdGroupOperation adGroupOperation : adGroupOperations) {
        long adGroupId = adGroupOperation.getOperand().getId();
        AdGroupAd adGroupAd = new AdGroupAd();
        adGroupAd.setAdGroupId(adGroupId);
        ExpandedTextAd textAd = new ExpandedTextAd();
        textAd.setHeadlinePart1("Luxury Cruise to Mars");
        textAd.setHeadlinePart2("Visit the Red Planet in style.");
        textAd.setDescription("Low-gravity fun for everyone!");
        textAd.setFinalUrls(new String[] { "http://www.example.com/1" });
        adGroupAd.setAd(textAd);
        AdGroupAdOperation operation = new AdGroupAdOperation();
        operation.setOperator(Operator.ADD);
        operation.setOperand(adGroupAd);
        operations.add(operation);
    }
    return operations;
}
Also used : AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) ArrayList(java.util.ArrayList) ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 2 with ExpandedTextAd

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

the class AddExpandedTextAds method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where the ad 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.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    List<AdGroupAdOperation> operations = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_ADS; i++) {
        // Create expanded text ad.
        ExpandedTextAd expandedTextAd = new ExpandedTextAd();
        expandedTextAd.setHeadlinePart1(String.format("Cruise #%d to Mars", i));
        expandedTextAd.setHeadlinePart2("Best Space Cruise Line");
        expandedTextAd.setHeadlinePart3("For Your Loved Ones");
        expandedTextAd.setDescription("Buy your tickets now!");
        expandedTextAd.setDescription2("Discount ends soon");
        expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/" + i });
        // Create ad group ad.
        AdGroupAd expandedTextAdGroupAd = new AdGroupAd();
        expandedTextAdGroupAd.setAdGroupId(adGroupId);
        expandedTextAdGroupAd.setAd(expandedTextAd);
        // Optional: set the status.
        expandedTextAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
        // Create the operation.
        AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
        adGroupAdOperation.setOperand(expandedTextAdGroupAd);
        adGroupAdOperation.setOperator(Operator.ADD);
        operations.add(adGroupAdOperation);
    }
    // Add ads.
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations.toArray(new AdGroupAdOperation[operations.size()]));
    // Display ads.
    Arrays.stream(result.getValue()).map(adGroupAdResult -> (ExpandedTextAd) adGroupAdResult.getAd()).forEach(newAd -> System.out.printf("Expanded text ad with ID %d and headline '%s | %s%s' was added.%n", newAd.getId(), newAd.getHeadlinePart1(), newAd.getHeadlinePart2(), newAd.getHeadlinePart3() == null ? "" : String.format(" | %s", newAd.getHeadlinePart3())));
}
Also used : Arrays(java.util.Arrays) Parameter(com.beust.jcommander.Parameter) ArrayList(java.util.ArrayList) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) ArgumentNames(com.google.api.ads.adwords.lib.utils.examples.ArgumentNames) Credential(com.google.api.client.auth.oauth2.Credential) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdStatus(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdStatus) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) Operator(com.google.api.ads.adwords.axis.v201809.cm.Operator) CodeSampleParams(com.google.api.ads.common.lib.utils.examples.CodeSampleParams) ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) RemoteException(java.rmi.RemoteException) DEFAULT_CONFIGURATION_FILENAME(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) List(java.util.List) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ArrayList(java.util.ArrayList) ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)

Example 3 with ExpandedTextAd

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

the class GetExpandedTextAds method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to use to find expanded text ads.
 * @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 adGroupId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.Status, AdGroupAdField.HeadlinePart1, AdGroupAdField.HeadlinePart2, AdGroupAdField.Description).orderAscBy(AdGroupAdField.Id).offset(offset).limit(PAGE_SIZE).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).in(AdGroupAdField.Status, "ENABLED", "PAUSED").equals("AdType", "EXPANDED_TEXT_AD").build();
    while (morePages) {
        // Get all ads.
        AdGroupAdPage page = adGroupAdService.get(selector);
        // Display ads.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            for (AdGroupAd adGroupAd : page.getEntries()) {
                ExpandedTextAd expandedTextAd = (ExpandedTextAd) adGroupAd.getAd();
                System.out.printf("Expanded text ad with ID %d, status '%s', and headline '%s - %s' was found.%n", adGroupAd.getAd().getId(), adGroupAd.getStatus(), expandedTextAd.getHeadlinePart1(), expandedTextAd.getHeadlinePart2());
            }
        } else {
            System.out.println("No expanded text ads were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 4 with ExpandedTextAd

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

the class UpdateExpandedTextAd method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adId the ID of the ad to update.
 * @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 adId) throws RemoteException {
    // Get the AdService.
    AdServiceInterface adService = adWordsServices.get(session, AdServiceInterface.class);
    // Creates an expanded text ad using the provided ad ID.
    ExpandedTextAd expandedTextAd = new ExpandedTextAd();
    expandedTextAd.setId(adId);
    // Updates some properties of the expanded text ad.
    expandedTextAd.setHeadlinePart1("Cruise to Pluto #" + System.currentTimeMillis());
    expandedTextAd.setHeadlinePart2("Tickets on sale now");
    expandedTextAd.setDescription("Best space cruise ever.");
    expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/" });
    expandedTextAd.setFinalMobileUrls(new String[] { "http://www.example.com/mobile" });
    // Creates ad group ad operation and adds it to the list.
    AdOperation operation = new AdOperation();
    operation.setOperator(Operator.SET);
    operation.setOperand(expandedTextAd);
    // Updates the ad on the server.
    ExpandedTextAd updatedAd = (ExpandedTextAd) adService.mutate(new AdOperation[] { operation }).getValue(0);
    // Prints out some information.
    System.out.printf("Expanded text ad with ID %d was updated.%n", updatedAd.getId());
    System.out.printf("Headline part 1 is '%s'.%nHeadline part 2 is '%s'.%nDescription is '%s'.%n", updatedAd.getHeadlinePart1(), updatedAd.getHeadlinePart2(), updatedAd.getDescription());
    System.out.printf("Final URL is '%s'.%nFinal mobile URL is '%s'.%n", updatedAd.getFinalUrls()[0], updatedAd.getFinalMobileUrls()[0]);
}
Also used : ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) AdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdOperation) AdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdServiceInterface)

Example 5 with ExpandedTextAd

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

the class AddAdCustomizer method createAdsWithCustomizations.

/**
 * Creates expanded text ads that use ad customizations for the specified ad group IDs.
 */
private static void createAdsWithCustomizations(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, String feedName) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    ExpandedTextAd textAd = new ExpandedTextAd();
    textAd.setHeadlinePart1(String.format("Luxury Cruise to {=%s.Name}", feedName));
    textAd.setHeadlinePart2(String.format("Only {=%s.Price}", feedName));
    textAd.setDescription(String.format("Offer ends in {=countdown(%s.Date)}!", feedName));
    textAd.setFinalUrls(new String[] { "http://www.example.com" });
    // We add the same ad to both ad groups. When they serve, they will show different values, since
    // they match different feed items.
    List<AdGroupAdOperation> adGroupAdOperations = new ArrayList<>();
    for (Long adGroupId : adGroupIds) {
        AdGroupAd adGroupAd = new AdGroupAd();
        adGroupAd.setAdGroupId(adGroupId);
        adGroupAd.setAd(textAd);
        AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
        adGroupAdOperation.setOperand(adGroupAd);
        adGroupAdOperation.setOperator(Operator.ADD);
        adGroupAdOperations.add(adGroupAdOperation);
    }
    AdGroupAdReturnValue adGroupAdReturnValue = adGroupAdService.mutate(adGroupAdOperations.toArray(new AdGroupAdOperation[adGroupAdOperations.size()]));
    for (AdGroupAd addedAd : adGroupAdReturnValue.getValue()) {
        System.out.printf("Created an ad with ID %d, type '%s' and status '%s'.%n", addedAd.getAd().getId(), addedAd.getAd().getAdType(), addedAd.getStatus());
    }
}
Also used : AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ArrayList(java.util.ArrayList) ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)

Aggregations

ExpandedTextAd (com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd)7 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)6 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)5 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)5 ArrayList (java.util.ArrayList)3 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)2 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 Parameter (com.beust.jcommander.Parameter)1 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)1 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)1 AdGroupAdStatus (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdStatus)1 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)1 AdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdOperation)1 AdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdServiceInterface)1 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 CustomParameter (com.google.api.ads.adwords.axis.v201809.cm.CustomParameter)1 CustomParameters (com.google.api.ads.adwords.axis.v201809.cm.CustomParameters)1 Operator (com.google.api.ads.adwords.axis.v201809.cm.Operator)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1