Search in sources :

Example 11 with Keyword

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

the class GetCampaignTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @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) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(CampaignCriterionField.CampaignId, CampaignCriterionField.Id, CampaignCriterionField.CriteriaType, CampaignCriterionField.PlatformName, CampaignCriterionField.LanguageName, CampaignCriterionField.LocationName, CampaignCriterionField.KeywordText).in(CampaignCriterionField.CriteriaType, "KEYWORD", "LANGUAGE", "LOCATION", "PLATFORM").offset(0).limit(PAGE_SIZE).build();
    CampaignCriterionPage page = null;
    do {
        page = campaignCriterionService.get(selector);
        if (page.getEntries() != null) {
            // Display campaigns.
            for (CampaignCriterion campaignCriterion : page.getEntries()) {
                System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was found.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
            }
        } else {
            System.out.println("No campaign criteria were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) CampaignCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 12 with Keyword

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

the class AxisBatchJobUploadBodyProviderTest method addCampaignNegativeKeywordOperation.

@Override
protected void addCampaignNegativeKeywordOperation(BatchJobMutateRequest request, long campaignId, String keywordText, String keywordMatchType) {
    Keyword keyword = new Keyword();
    keyword.setText(keywordText);
    keyword.setMatchType(KeywordMatchType.fromString(keywordMatchType));
    NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(keyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion)

Example 13 with Keyword

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

the class JaxWsBatchJobUploadBodyProviderTest method addCampaignNegativeKeywordOperation.

@Override
protected void addCampaignNegativeKeywordOperation(BatchJobMutateRequest request, long campaignId, String keywordText, String keywordMatchType) {
    Keyword keyword = new Keyword();
    keyword.setText(keywordText);
    keyword.setMatchType(KeywordMatchType.valueOf(keywordMatchType));
    NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(keyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : CampaignCriterionOperation(com.google.api.ads.adwords.jaxws.v201809.cm.CampaignCriterionOperation) Keyword(com.google.api.ads.adwords.jaxws.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.NegativeCampaignCriterion)

Example 14 with Keyword

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

the class FindAndRemoveCriteriaFromSharedSet method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign to use to find shared sets.
 * @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 CampaignSharedSetService.
    CampaignSharedSetServiceInterface campaignSharedSetService = adWordsServices.get(session, CampaignSharedSetServiceInterface.class);
    // First, retrieve all shared sets associated with the campaign.
    int offset = 0;
    SelectorBuilder selectorBuilder = new SelectorBuilder().fields(CampaignSharedSetField.SharedSetId, CampaignSharedSetField.CampaignId, CampaignSharedSetField.SharedSetName, CampaignSharedSetField.SharedSetType).equals(CampaignSharedSetField.CampaignId, campaignId.toString()).in(CampaignSharedSetField.SharedSetType, SharedSetType.NEGATIVE_KEYWORDS.getValue(), SharedSetType.NEGATIVE_PLACEMENTS.getValue()).limit(PAGE_SIZE);
    List<Long> sharedSetIds = new ArrayList<>();
    CampaignSharedSetPage campaignSharedSetPage;
    do {
        selectorBuilder.offset(offset);
        campaignSharedSetPage = campaignSharedSetService.get(selectorBuilder.build());
        for (CampaignSharedSet campaignSharedSet : campaignSharedSetPage.getEntries()) {
            sharedSetIds.add(campaignSharedSet.getSharedSetId());
            System.out.printf("Campaign shared set ID %d and name '%s' found for campaign ID %d.%n", campaignSharedSet.getSharedSetId(), campaignSharedSet.getSharedSetName(), campaignSharedSet.getCampaignId());
        }
        offset += PAGE_SIZE;
    } while (offset < campaignSharedSetPage.getTotalNumEntries());
    if (sharedSetIds.isEmpty()) {
        System.out.printf("No shared sets found for campaign ID %d.%n", campaignId);
        return;
    }
    // Next, retrieve criterion IDs for all found shared sets.
    SharedCriterionServiceInterface sharedCriterionService = adWordsServices.get(session, SharedCriterionServiceInterface.class);
    // Transform shared set IDs to strings.
    String[] sharedSetIdStrings = Collections2.transform(sharedSetIds, Functions.toStringFunction()).toArray(new String[sharedSetIds.size()]);
    offset = 0;
    selectorBuilder = new SelectorBuilder().fields("SharedSetId", "Id", "KeywordText", "KeywordMatchType", "PlacementUrl").in("SharedSetId", sharedSetIdStrings).limit(PAGE_SIZE);
    List<SharedCriterionOperation> removeCriterionOperations = new ArrayList<>();
    SharedCriterionPage sharedCriterionPage;
    do {
        selectorBuilder.offset(offset);
        sharedCriterionPage = sharedCriterionService.get(selectorBuilder.build());
        for (SharedCriterion sharedCriterion : sharedCriterionPage.getEntries()) {
            if (CriterionType.KEYWORD.equals(sharedCriterion.getCriterion().getType())) {
                Keyword keyword = (Keyword) sharedCriterion.getCriterion();
                System.out.printf("Shared negative keyword with ID %d and text '%s' was found.%n", keyword.getId(), keyword.getText());
            } else if (CriterionType.PLACEMENT.equals(sharedCriterion.getCriterion().getType())) {
                Placement placement = (Placement) sharedCriterion.getCriterion();
                System.out.printf("Shared negative placement with ID %d and URL '%s' was found.%n", placement.getId(), placement.getUrl());
            } else {
                System.out.printf("Shared criterion with ID %d was found.%n", sharedCriterion.getCriterion().getId());
            }
            // Create an operation to remove this criterion.
            SharedCriterionOperation removeCriterionOperation = new SharedCriterionOperation();
            removeCriterionOperation.setOperator(Operator.REMOVE);
            SharedCriterion sharedCriterionToRemove = new SharedCriterion();
            Criterion criterionToRemove = new Criterion();
            criterionToRemove.setId(sharedCriterion.getCriterion().getId());
            sharedCriterionToRemove.setCriterion(criterionToRemove);
            sharedCriterionToRemove.setSharedSetId(sharedCriterion.getSharedSetId());
            removeCriterionOperation.setOperand(sharedCriterionToRemove);
            removeCriterionOperations.add(removeCriterionOperation);
        }
        offset += PAGE_SIZE;
    } while (offset < sharedCriterionPage.getTotalNumEntries());
    // Finally, remove the criteria.
    if (removeCriterionOperations.isEmpty()) {
        System.out.printf("No shared criteria to remove.%n");
    } else {
        SharedCriterionReturnValue sharedCriterionReturnValue = sharedCriterionService.mutate(removeCriterionOperations.toArray(new SharedCriterionOperation[removeCriterionOperations.size()]));
        for (SharedCriterion removedCriterion : sharedCriterionReturnValue.getValue()) {
            System.out.printf("Shared criterion ID %d was successfully removed from shared set ID %d.%n", removedCriterion.getCriterion().getId(), removedCriterion.getSharedSetId());
        }
    }
}
Also used : CampaignSharedSetPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignSharedSetPage) SharedCriterion(com.google.api.ads.adwords.axis.v201809.cm.SharedCriterion) CampaignSharedSetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignSharedSetServiceInterface) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) ArrayList(java.util.ArrayList) SharedCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.SharedCriterionOperation) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) Placement(com.google.api.ads.adwords.axis.v201809.cm.Placement) SharedCriterion(com.google.api.ads.adwords.axis.v201809.cm.SharedCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) CampaignSharedSet(com.google.api.ads.adwords.axis.v201809.cm.CampaignSharedSet) SharedCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.SharedCriterionReturnValue) SharedCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.SharedCriterionServiceInterface) SharedCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.SharedCriterionPage)

Example 15 with Keyword

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

the class EstimateKeywordTraffic method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @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) throws RemoteException {
    // Get the TrafficEstimatorService.
    TrafficEstimatorServiceInterface trafficEstimatorService = adWordsServices.get(session, TrafficEstimatorServiceInterface.class);
    // Create keywords. Refer to the TrafficEstimatorService documentation for the maximum
    // number of keywords that can be passed in a single request.
    // https://developers.google.com/adwords/api/docs/reference/latest/TrafficEstimatorService
    List<Keyword> keywords = new ArrayList<Keyword>();
    Keyword marsCruiseKeyword = new Keyword();
    marsCruiseKeyword.setText("mars cruise");
    marsCruiseKeyword.setMatchType(KeywordMatchType.BROAD);
    keywords.add(marsCruiseKeyword);
    Keyword cheapCruiseKeyword = new Keyword();
    cheapCruiseKeyword.setText("cheap cruise");
    cheapCruiseKeyword.setMatchType(KeywordMatchType.PHRASE);
    keywords.add(cheapCruiseKeyword);
    Keyword cruiseKeyword = new Keyword();
    cruiseKeyword.setText("cruise");
    cruiseKeyword.setMatchType(KeywordMatchType.EXACT);
    keywords.add(cruiseKeyword);
    // Create a keyword estimate request for each keyword.
    List<KeywordEstimateRequest> keywordEstimateRequests = keywords.stream().map(keyword -> {
        KeywordEstimateRequest keywordEstimateRequest = new KeywordEstimateRequest();
        keywordEstimateRequest.setKeyword(keyword);
        return keywordEstimateRequest;
    }).collect(Collectors.toList());
    // Add a negative keyword to the traffic estimate.
    KeywordEstimateRequest negativeKeywordEstimateRequest = new KeywordEstimateRequest();
    negativeKeywordEstimateRequest.setKeyword(new Keyword(null, null, null, "hiking tour", KeywordMatchType.BROAD));
    negativeKeywordEstimateRequest.setIsNegative(true);
    keywordEstimateRequests.add(negativeKeywordEstimateRequest);
    // Create ad group estimate requests.
    List<AdGroupEstimateRequest> adGroupEstimateRequests = new ArrayList<AdGroupEstimateRequest>();
    AdGroupEstimateRequest adGroupEstimateRequest = new AdGroupEstimateRequest();
    adGroupEstimateRequest.setKeywordEstimateRequests(keywordEstimateRequests.toArray(new KeywordEstimateRequest[] {}));
    adGroupEstimateRequest.setMaxCpc(new Money(null, 1000000L));
    adGroupEstimateRequests.add(adGroupEstimateRequest);
    // Create campaign estimate requests.
    List<CampaignEstimateRequest> campaignEstimateRequests = new ArrayList<CampaignEstimateRequest>();
    CampaignEstimateRequest campaignEstimateRequest = new CampaignEstimateRequest();
    campaignEstimateRequest.setAdGroupEstimateRequests(adGroupEstimateRequests.toArray(new AdGroupEstimateRequest[] {}));
    Location unitedStates = new Location();
    unitedStates.setId(2840L);
    Language english = new Language();
    english.setId(1000L);
    campaignEstimateRequest.setCriteria(new Criterion[] { unitedStates, english });
    campaignEstimateRequests.add(campaignEstimateRequest);
    // Create selector.
    TrafficEstimatorSelector selector = new TrafficEstimatorSelector();
    selector.setCampaignEstimateRequests(campaignEstimateRequests.toArray(new CampaignEstimateRequest[] {}));
    // Optional: Request a list of campaign level estimates segmented by platform.
    selector.setPlatformEstimateRequested(true);
    // Get traffic estimates.
    TrafficEstimatorResult result = trafficEstimatorService.get(selector);
    // Display traffic estimates.
    if (result != null && result.getCampaignEstimates() != null && result.getCampaignEstimates().length > 0) {
        CampaignEstimate campaignEstimate = result.getCampaignEstimates()[0];
        // Display the campaign level estimates segmented by platform.
        if (campaignEstimate.getPlatformEstimates() != null) {
            for (PlatformCampaignEstimate platformEstimate : campaignEstimate.getPlatformEstimates()) {
                String platformMessage = String.format("Results for the platform with ID %d and name '%s':%n", platformEstimate.getPlatform().getId(), platformEstimate.getPlatform().getPlatformName());
                displayMeanEstimates(platformMessage, platformEstimate.getMinEstimate(), platformEstimate.getMaxEstimate());
            }
        }
        // Display the keyword estimates.
        KeywordEstimate[] keywordEstimates = campaignEstimate.getAdGroupEstimates()[0].getKeywordEstimates();
        for (int i = 0; i < keywordEstimates.length; i++) {
            if (Boolean.TRUE.equals(keywordEstimateRequests.get(i).getIsNegative())) {
                continue;
            }
            Keyword keyword = keywordEstimateRequests.get(i).getKeyword();
            KeywordEstimate keywordEstimate = keywordEstimates[i];
            String keywordMessage = String.format("Results for the keyword with text '%s' and match type '%s':%n", keyword.getText(), keyword.getMatchType());
            displayMeanEstimates(keywordMessage, keywordEstimate.getMin(), keywordEstimate.getMax());
        }
    } else {
        System.out.println("No traffic estimates were returned.");
    }
}
Also used : TrafficEstimatorServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorServiceInterface) TrafficEstimatorResult(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorResult) KeywordMatchType(com.google.api.ads.adwords.axis.v201809.cm.KeywordMatchType) AdGroupEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.AdGroupEstimateRequest) ArrayList(java.util.ArrayList) CampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimate) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) Credential(com.google.api.client.auth.oauth2.Credential) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) Collectors(java.util.stream.Collectors) RemoteException(java.rmi.RemoteException) DEFAULT_CONFIGURATION_FILENAME(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME) 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) CampaignEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimateRequest) KeywordEstimate(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimate) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) Location(com.google.api.ads.adwords.axis.v201809.cm.Location) KeywordEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimateRequest) PlatformCampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.PlatformCampaignEstimate) TrafficEstimatorSelector(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorSelector) StatsEstimate(com.google.api.ads.adwords.axis.v201809.o.StatsEstimate) CampaignEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimateRequest) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) ArrayList(java.util.ArrayList) AdGroupEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.AdGroupEstimateRequest) KeywordEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimateRequest) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) PlatformCampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.PlatformCampaignEstimate) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) CampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimate) PlatformCampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.PlatformCampaignEstimate) TrafficEstimatorServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorServiceInterface) TrafficEstimatorResult(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorResult) TrafficEstimatorSelector(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorSelector) Location(com.google.api.ads.adwords.axis.v201809.cm.Location) KeywordEstimate(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimate)

Aggregations

Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)12 ArrayList (java.util.ArrayList)10 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)6 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)5 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)4 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)4 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)4 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)4 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)3 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)3 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)3 Language (com.google.api.ads.adwords.axis.v201809.cm.Language)3 Location (com.google.api.ads.adwords.axis.v201809.cm.Location)3 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)3 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)3 Parameter (com.beust.jcommander.Parameter)2 BatchJobHelper (com.google.api.ads.adwords.axis.utils.v201809.batchjob.BatchJobHelper)2 BatchJobMutateResponse (com.google.api.ads.adwords.axis.utils.v201809.batchjob.BatchJobMutateResponse)2