Search in sources :

Example 1 with AdGroupAdServiceInterface

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

the class GetAllDisapprovedAds method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to search for disapproved 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;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.PolicySummary).orderAscBy(AdGroupAdField.Id).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).equals(AdGroupAdField.CombinedApprovalStatus, PolicyApprovalStatus.DISAPPROVED.toString()).offset(offset).limit(PAGE_SIZE).build();
    // Get all disapproved ads.
    AdGroupAdPage page = null;
    int disapprovedAdsCount = 0;
    do {
        page = adGroupAdService.get(selector);
        // Display ads.
        for (AdGroupAd adGroupAd : page) {
            disapprovedAdsCount++;
            AdGroupAdPolicySummary policySummary = adGroupAd.getPolicySummary();
            System.out.printf("Ad with ID %d and type '%s' was disapproved with the following " + "policy topic entries:%n", adGroupAd.getAd().getId(), adGroupAd.getAd().getAdType());
            // Display the policy topic entries related to the ad disapproval.
            for (PolicyTopicEntry policyTopicEntry : policySummary.getPolicyTopicEntries()) {
                System.out.printf("  topic id: %s, topic name: '%s', Help Center URL: %s%n", policyTopicEntry.getPolicyTopicId(), policyTopicEntry.getPolicyTopicName(), policyTopicEntry.getPolicyTopicHelpCenterUrl());
                // Display the attributes and values that triggered the policy topic.
                if (policyTopicEntry.getPolicyTopicEvidences() != null) {
                    for (PolicyTopicEvidence evidence : policyTopicEntry.getPolicyTopicEvidences()) {
                        System.out.printf("    evidence type: %s%n", evidence.getPolicyTopicEvidenceType());
                        if (evidence.getEvidenceTextList() != null) {
                            for (int i = 0; i < evidence.getEvidenceTextList().length; i++) {
                                System.out.printf("      evidence text[%d]: %s%n", i, evidence.getEvidenceTextList(i));
                            }
                        }
                    }
                }
            }
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
    System.out.printf("%d disapproved ads were found.%n", disapprovedAdsCount);
}
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) PolicyTopicEvidence(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEvidence) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) PolicyTopicEntry(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEntry) AdGroupAdPolicySummary(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 2 with AdGroupAdServiceInterface

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

the class AddDynamicSearchAdsCampaign method createExpandedDSA.

/**
 * Creates the expanded Dynamic Search Ad.
 */
private static void createExpandedDSA(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Create the expanded Dynamic Search Ad. This ad will have its headline and final URL
    // auto-generated at serving time according to domain name specific information provided
    // by DynamicSearchAdsSetting at the campaign level.
    ExpandedDynamicSearchAd expandedDSA = new ExpandedDynamicSearchAd();
    // Set the ad description.
    expandedDSA.setDescription("Buy your tickets now!");
    expandedDSA.setDescription2("Discount ends soon");
    // Create the ad group ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroup.getId());
    adGroupAd.setAd(expandedDSA);
    // Optional: Set the status.
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create the operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(adGroupAd);
    // Create the ad.
    AdGroupAd newAdGroupAd = adGroupAdService.mutate(new AdGroupAdOperation[] { operation }).getValue(0);
    ExpandedDynamicSearchAd newExpandedDSA = (ExpandedDynamicSearchAd) newAdGroupAd.getAd();
    System.out.printf("Expanded Dynamic Search Ad with ID %d and description '%s' and description 2 '%s' was " + "added.%n", newExpandedDSA.getId(), newExpandedDSA.getDescription(), newExpandedDSA.getDescription2());
}
Also used : AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) ExpandedDynamicSearchAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedDynamicSearchAd)

Example 3 with AdGroupAdServiceInterface

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

the class AddGmailAd 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.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws IOException {
    // This ad format does not allow the creation of an image using the
    // Image.data field. An image must first be created using the MediaService,
    // and Image.mediaId must be populated when creating the ad.
    long logoImageId = uploadImage(adWordsServices, session, "https://goo.gl/mtt54n");
    Image logoImage = new Image();
    logoImage.setMediaId(logoImageId);
    long marketingImageId = uploadImage(adWordsServices, session, "http://goo.gl/3b9Wfh");
    Image adImage = new Image();
    adImage.setMediaId(marketingImageId);
    GmailTeaser teaser = new GmailTeaser();
    teaser.setHeadline("Dream");
    teaser.setDescription("Create your own adventure");
    teaser.setBusinessName("Interplanetary Ships");
    teaser.setLogoImage(logoImage);
    // Create the Gmail ad.
    GmailAd gmailAd = new GmailAd();
    gmailAd.setTeaser(teaser);
    gmailAd.setMarketingImage(adImage);
    gmailAd.setMarketingImageHeadline("Travel");
    gmailAd.setMarketingImageDescription("Take to the skies!");
    gmailAd.setFinalUrls(new String[] { "http://www.example.com" });
    // Create ad group ad for the Gmail ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(gmailAd);
    // Additional properties (non-required).
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(adGroupAd);
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Add Gmail ad.
    AdGroupAdReturnValue returnValue = adGroupAdService.mutate(new AdGroupAdOperation[] { operation });
    if (returnValue.getValue() != null) {
        for (AdGroupAd newAdGroupAd : returnValue.getValue()) {
            System.out.printf("New Gmail ad with ID %d and headline '%s' was added.%n", newAdGroupAd.getAd().getId(), ((GmailAd) newAdGroupAd.getAd()).getTeaser().getHeadline());
        }
    } else {
        System.out.println("No Gmail ads were added.");
    }
}
Also used : GmailAd(com.google.api.ads.adwords.axis.v201809.cm.GmailAd) 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) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) Image(com.google.api.ads.adwords.axis.v201809.cm.Image) GmailTeaser(com.google.api.ads.adwords.axis.v201809.cm.GmailTeaser)

Example 4 with AdGroupAdServiceInterface

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

the class AddMultiAssetResponsiveDisplayAd 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.
 * @throws IOException if unable to retrieve an image from a URL.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws IOException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    List<AdGroupAdOperation> operations = new ArrayList<>();
    MultiAssetResponsiveDisplayAd ad = new MultiAssetResponsiveDisplayAd();
    List<AssetLink> headlines = new ArrayList<>();
    headlines.add(createAssetLinkForText("Travel to Mars"));
    headlines.add(createAssetLinkForText("Travel to Jupiter"));
    headlines.add(createAssetLinkForText("Travel to Pluto"));
    headlines.add(createAssetLinkForText("Experience the Stars"));
    ad.setHeadlines(headlines.toArray(new AssetLink[0]));
    List<AssetLink> descriptions = new ArrayList<>();
    descriptions.add(createAssetLinkForText("Visit the planet in a luxury spaceship."));
    descriptions.add(createAssetLinkForText("See the planet in style."));
    ad.setDescriptions(descriptions.toArray(new AssetLink[0]));
    ad.setBusinessName("Galactic Luxury Cruises");
    ad.setLongHeadline(createAssetLinkForText("Visit the planet in a luxury spaceship."));
    // This ad format does not allow the creation of an image asset by setting the asset.imageData
    // field. An image asset must first be created using the AssetService, and asset.assetId must be
    // populated when creating the ad.
    ad.setMarketingImages(new AssetLink[] { createAssetLinkForImageAsset(uploadImageAsset(adWordsServices, session, "https://goo.gl/3b9Wfh")) });
    ad.setSquareMarketingImages(new AssetLink[] { createAssetLinkForImageAsset(uploadImageAsset(adWordsServices, session, "https://goo.gl/mtt54n")) });
    ad.setFinalUrls(new String[] { "http://www.example.com" });
    // Optional: set call to action text.
    ad.setCallToActionText("Shop Now");
    // Set color settings using hexadecimal values. Set allowFlexibleColor to false if you want
    // your ads to render by always using your colors strictly.
    ad.setMainColor("#0000ff");
    ad.setAccentColor("#ffff00");
    ad.setAllowFlexibleColor(false);
    // Set the format setting that the ad will be served in.
    ad.setFormatSetting(DisplayAdFormatSetting.NON_NATIVE);
    // Optional: Set dynamic display ad settings, composed of landscape logo image, promotion text,
    // and price prefix.
    ad.setDynamicSettingsPricePrefix("as low as");
    ad.setDynamicSettingsPromoText("Free shipping!");
    ad.setLogoImages(new AssetLink[] { createAssetLinkForImageAsset(uploadImageAsset(adWordsServices, session, "https://goo.gl/mtt54n")) });
    // Create ad group ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(ad);
    // Optional: set the status.
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create the operation.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
    adGroupAdOperation.setOperand(adGroupAd);
    adGroupAdOperation.setOperator(Operator.ADD);
    operations.add(adGroupAdOperation);
    // Add ad.
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations.toArray(new AdGroupAdOperation[operations.size()]));
    Arrays.stream(result.getValue()).map(adGroupAdResult -> (MultiAssetResponsiveDisplayAd) adGroupAdResult.getAd()).forEach(newAd -> System.out.printf("New responsive display ad with ID %d and long headline '%s' was added.%n", newAd.getId(), ((TextAsset) newAd.getLongHeadline().getAsset()).getAssetText()));
}
Also used : Arrays(java.util.Arrays) Parameter(com.beust.jcommander.Parameter) ArrayList(java.util.ArrayList) AssetLink(com.google.api.ads.adwords.axis.v201809.cm.AssetLink) AssetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) AssetOperation(com.google.api.ads.adwords.axis.v201809.cm.AssetOperation) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset) 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) DisplayAdFormatSetting(com.google.api.ads.adwords.axis.v201809.cm.DisplayAdFormatSetting) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) IOException(java.io.IOException) Operator(com.google.api.ads.adwords.axis.v201809.cm.Operator) CodeSampleParams(com.google.api.ads.common.lib.utils.examples.CodeSampleParams) 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) MultiAssetResponsiveDisplayAd(com.google.api.ads.adwords.axis.v201809.cm.MultiAssetResponsiveDisplayAd) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) TextAsset(com.google.api.ads.adwords.axis.v201809.cm.TextAsset) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) TextAsset(com.google.api.ads.adwords.axis.v201809.cm.TextAsset) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) MultiAssetResponsiveDisplayAd(com.google.api.ads.adwords.axis.v201809.cm.MultiAssetResponsiveDisplayAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ArrayList(java.util.ArrayList) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) AssetLink(com.google.api.ads.adwords.axis.v201809.cm.AssetLink)

Example 5 with AdGroupAdServiceInterface

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

the class AddShoppingDynamicRemarketingCampaign method createAd.

/**
 * Creates an ad for serving dynamic content in a remarketing campaign.
 *
 * @param adGroup the ad group under which to create the ad.
 * @return the ad that was created.
 * @throws IOException if an image was not able to be loaded.
 */
private static AdGroupAd createAd(AdWordsServicesInterface services, AdWordsSession session, AdGroup adGroup) throws IOException {
    AdGroupAdServiceInterface adService = services.get(session, AdGroupAdServiceInterface.class);
    ResponsiveDisplayAd ad = new ResponsiveDisplayAd();
    // This ad format does not allow the creation of an image using the
    // Image.data field. An image must first be created using the MediaService,
    // and Image.mediaId must be populated when creating the ad.
    ad.setMarketingImage(uploadImage(services, session, "https://goo.gl/3b9Wfh"));
    ad.setShortHeadline("Travel");
    ad.setLongHeadline("Travel the World");
    ad.setDescription("Take to the air!");
    ad.setBusinessName("Interplanetary Cruises");
    ad.setFinalUrls(new String[] { "http://www.example.com/" });
    // Optional: Call to action text.
    // Valid texts: https://support.google.com/adwords/answer/7005917
    ad.setCallToActionText("Apply Now");
    // Optional: Set dynamic display ad settings, composed of landscape logo
    // image, promotion text, and price prefix.
    DynamicSettings dynamicDisplayAdSettings = createDynamicDisplayAdSettings(services, session);
    ad.setDynamicDisplayAdSettings(dynamicDisplayAdSettings);
    Image optionalImage = uploadImage(services, session, "https://goo.gl/mtt54n");
    // Optional: Create a logo image and set it to the ad.
    ad.setLogoImage(optionalImage);
    // Optional: Create a square marketing image and set it to the ad.
    ad.setSquareMarketingImage(optionalImage);
    // Whitelisted accounts only: Set color settings using hexadecimal values.
    // Set allowFlexibleColor to false if you want your ads to render by always
    // using your colors strictly.
    /*
    ad.setMainColor("#0000ff");
    ad.setAccentColor("#ffff00");
    ad.setAllowFlexibleColor(false);
    */
    // Whitelisted accounts only: Set the format setting that the ad will be
    // served in.
    /*
    ad.setFormatSetting(
        com.google.api.ads.adwords.axis.v201809.cm.DisplayAdFormatSetting.NON_NATIVE);
    */
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAd(ad);
    adGroupAd.setAdGroupId(adGroup.getId());
    AdGroupAdOperation op = new AdGroupAdOperation();
    op.setOperand(adGroupAd);
    op.setOperator(Operator.ADD);
    AdGroupAdReturnValue result = adService.mutate(new AdGroupAdOperation[] { op });
    return result.getValue(0);
}
Also used : ResponsiveDisplayAd(com.google.api.ads.adwords.axis.v201809.cm.ResponsiveDisplayAd) 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) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) Image(com.google.api.ads.adwords.axis.v201809.cm.Image) DynamicSettings(com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings)

Aggregations

AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)19 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)19 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)15 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)12 ExpandedTextAd (com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd)5 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)4 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)4 ArrayList (java.util.ArrayList)4 Parameter (com.beust.jcommander.Parameter)3 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)3 AdGroupAdStatus (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdStatus)3 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)3 AssetLink (com.google.api.ads.adwords.axis.v201809.cm.AssetLink)3 Image (com.google.api.ads.adwords.axis.v201809.cm.Image)3 Operator (com.google.api.ads.adwords.axis.v201809.cm.Operator)3 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)3 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)3 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)3 ArgumentNames (com.google.api.ads.adwords.lib.utils.examples.ArgumentNames)3