Search in sources :

Example 66 with Ad

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

the class ValidateTextAd method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group for the ad.
 * @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 {
    // Enable validation.
    session.setValidateOnly(true);
    // Get the validation AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdValidationService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Create text ad.
    ExpandedTextAd textAd1 = new ExpandedTextAd();
    textAd1.setHeadlinePart1("Luxury Cruise to Mars");
    textAd1.setHeadlinePart2("Visit the Red Planet in style.");
    textAd1.setDescription("Low-gravity fun for everyone!");
    textAd1.setFinalUrls(new String[] { "http://www.example.com" });
    // Create ad group ad.
    AdGroupAd textAdGroupAd1 = new AdGroupAd();
    textAdGroupAd1.setAdGroupId(adGroupId);
    textAdGroupAd1.setAd(textAd1);
    // Create operations.
    AdGroupAdOperation textAdGroupAdOperation1 = new AdGroupAdOperation();
    textAdGroupAdOperation1.setOperand(textAdGroupAd1);
    textAdGroupAdOperation1.setOperator(Operator.ADD);
    AdGroupAdOperation[] operations = new AdGroupAdOperation[] { textAdGroupAdOperation1 };
    // Add ads.
    adGroupAdValidationService.mutate(operations);
    // No error means the request is valid.
    // Now let's check an invalid ad using a very long line to trigger an error.
    textAd1.setDescription("Low-gravity fun for all astronauts in orbit.");
    try {
        adGroupAdValidationService.mutate(operations);
    } catch (ApiException e) {
        System.err.printf("Validation failed for the following reason: %s%n", e.getMessage());
    }
}
Also used : 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) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException)

Example 67 with Ad

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

the class AddCompleteCampaignsUsingBatchJob method buildAdGroupOperations.

private static List<AdGroupOperation> buildAdGroupOperations(Iterator<Long> tempIdGenerator, String namePrefix, Iterable<CampaignOperation> campaignOperations) {
    List<AdGroupOperation> operations = new ArrayList<>();
    for (CampaignOperation campaignOperation : campaignOperations) {
        for (int i = 0; i < NUMBER_OF_ADGROUPS_TO_ADD; i++) {
            AdGroup adGroup = new AdGroup();
            adGroup.setCampaignId(campaignOperation.getOperand().getId());
            adGroup.setId(tempIdGenerator.next());
            adGroup.setName(String.format("Batch Ad Group %s.%s", namePrefix, i));
            BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
            CpcBid bid = new CpcBid();
            bid.setBid(new Money(null, 10000000L));
            biddingStrategyConfiguration.setBids(new Bids[] { bid });
            adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
            AdGroupOperation operation = new AdGroupOperation();
            operation.setOperand(adGroup);
            operation.setOperator(Operator.ADD);
            operations.add(operation);
        }
    }
    return operations;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) ArrayList(java.util.ArrayList) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 68 with Ad

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

the class GetAllDisapprovedAdsWithAwql 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);
    ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(AdGroupAdField.Id, AdGroupAdField.PolicySummary).where(AdGroupAdField.AdGroupId).equalTo(adGroupId).where(AdGroupAdField.CombinedApprovalStatus).equalTo(PolicyApprovalStatus.DISAPPROVED.getValue()).orderBy(AdGroupAdField.Id, SortOrder.ASCENDING).limit(0, PAGE_SIZE).build();
    // Get all disapproved ads.
    AdGroupAdPage page = null;
    int disapprovedAdsCount = 0;
    do {
        serviceQuery.nextPage(page);
        page = adGroupAdService.query(serviceQuery.toString());
        // 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'%n", policyTopicEntry.getPolicyTopicId(), policyTopicEntry.getPolicyTopicName());
                // 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));
                            }
                        }
                    }
                }
            }
        }
    } while (serviceQuery.hasNext(page));
    System.out.printf("%d disapproved ads were found.%n", disapprovedAdsCount);
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) 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) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Example 69 with Ad

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

the class AddAdGroups method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where the ad groups 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 campaignId) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create ad group.
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
    adGroup.setStatus(AdGroupStatus.ENABLED);
    adGroup.setCampaignId(campaignId);
    // Optional settings.
    // Targeting restriction settings. Depending on the criterionTypeGroup
    // value, most TargetingSettingDetail only affect Display campaigns.
    // However, the USER_INTEREST_AND_LIST value works for RLSA campaigns -
    // Search campaigns targeting using a remarketing list.
    TargetingSetting targeting = new TargetingSetting();
    // Restricting to serve ads that match your ad group placements.
    // This is equivalent to choosing "Target and bid" in the UI.
    TargetingSettingDetail placements = new TargetingSettingDetail();
    placements.setCriterionTypeGroup(CriterionTypeGroup.PLACEMENT);
    placements.setTargetAll(Boolean.FALSE);
    // Using your ad group verticals only for bidding. This is equivalent
    // to choosing "Bid only" in the UI.
    TargetingSettingDetail verticals = new TargetingSettingDetail();
    verticals.setCriterionTypeGroup(CriterionTypeGroup.VERTICAL);
    verticals.setTargetAll(Boolean.TRUE);
    targeting.setDetails(new TargetingSettingDetail[] { placements, verticals });
    adGroup.setSettings(new Setting[] { targeting });
    // Set the rotation mode.
    AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode(AdRotationMode.OPTIMIZE);
    adGroup.setAdGroupAdRotationMode(rotationMode);
    // Create ad group bid.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    Money cpcBidMoney = new Money();
    cpcBidMoney.setMicroAmount(10_000_000L);
    CpcBid bid = new CpcBid();
    bid.setBid(cpcBidMoney);
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Add as many additional ad groups as you need.
    AdGroup adGroup2 = new AdGroup();
    adGroup2.setName("Earth to Venus Cruises #" + System.currentTimeMillis());
    adGroup2.setStatus(AdGroupStatus.ENABLED);
    adGroup2.setCampaignId(campaignId);
    BiddingStrategyConfiguration biddingStrategyConfiguration2 = new BiddingStrategyConfiguration();
    Money cpcBidMoney2 = new Money();
    cpcBidMoney2.setMicroAmount(10_000_000L);
    CpcBid bid2 = new CpcBid();
    bid2.setBid(cpcBidMoney2);
    biddingStrategyConfiguration2.setBids(new Bids[] { bid2 });
    adGroup2.setBiddingStrategyConfiguration(biddingStrategyConfiguration2);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.ADD);
    AdGroupOperation operation2 = new AdGroupOperation();
    operation2.setOperand(adGroup2);
    operation2.setOperator(Operator.ADD);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation, operation2 };
    // Add ad groups.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display new ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroupResult.getName(), adGroupResult.getId());
    }
}
Also used : TargetingSettingDetail(com.google.api.ads.adwords.axis.v201809.cm.TargetingSettingDetail) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) TargetingSetting(com.google.api.ads.adwords.axis.v201809.cm.TargetingSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupAdRotationMode(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdRotationMode) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 70 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad 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

AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)20 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)19 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)16 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)16 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)15 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 ArrayList (java.util.ArrayList)14 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)13 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)12 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)12 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)12 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)10 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)10 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)9 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)9 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)7 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)7