use of com.google.api.ads.adwords.axis.v201809.cm.DraftOperation 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());
}
Aggregations