Search in sources :

Example 1 with DraftServiceInterface

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

the class AddDraft method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param baseCampaignId the base campaign ID for the draft.
 * @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 baseCampaignId) throws RemoteException {
    // Get the DraftService.
    DraftServiceInterface draftService = adWordsServices.get(session, DraftServiceInterface.class);
    Draft draft = new Draft();
    draft.setBaseCampaignId(baseCampaignId);
    draft.setDraftName("Test Draft #" + System.currentTimeMillis());
    DraftOperation draftOperation = new DraftOperation();
    draftOperation.setOperator(Operator.ADD);
    draftOperation.setOperand(draft);
    draft = draftService.mutate(new DraftOperation[] { draftOperation }).getValue(0);
    System.out.printf("Draft with ID %d and base campaign ID %d and draft campaign ID %d created.%n", draft.getDraftId(), draft.getBaseCampaignId(), draft.getDraftCampaignId());
    // Once the draft is created, you can modify the draft campaign as if it
    // were a real campaign. For example, you may add criteria, adjust bids,
    // or even include additional ads. Adding a criterion is shown here.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    Language language = new Language();
    // Spanish
    language.setId(1003L);
    // Make sure to use the draftCampaignId when modifying the virtual draft campaign.
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(draft.getDraftCampaignId());
    campaignCriterion.setCriterion(language);
    CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
    criterionOperation.setOperator(Operator.ADD);
    criterionOperation.setOperand(campaignCriterion);
    campaignCriterion = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation }).getValue(0);
    System.out.printf("Draft updated to include criteria in draft campaign ID %d.%n", draft.getDraftCampaignId());
}
Also used : Draft(com.google.api.ads.adwords.axis.v201809.cm.Draft) DraftOperation(com.google.api.ads.adwords.axis.v201809.cm.DraftOperation) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) DraftServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DraftServiceInterface)

Aggregations

CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 Draft (com.google.api.ads.adwords.axis.v201809.cm.Draft)1 DraftOperation (com.google.api.ads.adwords.axis.v201809.cm.DraftOperation)1 DraftServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.DraftServiceInterface)1 Language (com.google.api.ads.adwords.axis.v201809.cm.Language)1